我找到了一个 Django 项目,但未能通过以下方式使其在 Docker 容器中运行:
git clone https://github.com/hotdogee/django-blast.git我有以下 Dockerfile:
FROM python:2
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
Run Code Online (Sandbox Code Playgroud)
对于docker-compose.yml我来说:
version: "3"
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
Run Code Online (Sandbox Code Playgroud)
接下来,我遇到了这个错误:
$ docker-compose build
...
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -c 'import …Run Code Online (Sandbox Code Playgroud) 我正在使用 fastcgi 在 nginx 之上运行 django。当我执行 runfcgi 时,我看到这些错误:
python manage.py runfcgi daemonize=false host=127.0.0.1 port=8000
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Run Code Online (Sandbox Code Playgroud)
在我的 nginx 错误日志中,我看到了这个:
2011/01/31 10:33:16 [error] 15921#0: *4 FastCGI sent in stderr: "WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while reading upstream, client: ::1, server: …Run Code Online (Sandbox Code Playgroud) 我有一个t1.micro带有公共 DNS的实例,类似于以下内容:
ec2-184-72-67-202.compute-1.amazonaws.com
Run Code Online (Sandbox Code Playgroud)
(部分数字已更改)
在本例中,我正在运行以下 Django 应用程序:
$ sudo python manage.py runserver --settings=vlists.settings.dev
Validating models...
0 errors found
Django version 1.4.1, using settings 'vlists.settings.dev'
Development server is running at http://127.0.0.1:8000/
Run Code Online (Sandbox Code Playgroud)
我已经port 8000通过 AWS 控制台打开了
:
当我在 Chrome 中导航到以下 URL 时,我收到消息Oops! Google Chrome could not connect to:
http://ec2-184-72-67-202.compute-1.amazonaws.com:8000
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
网络统计:
netstat -lan | grep 8000
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
Run Code Online (Sandbox Code Playgroud) 我对所有服务器技术都比较陌生,我按照本教程使用 mod_wsgi 在 Apache Web 服务器上部署我的 Django 应用程序:
http://thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/
这是我的虚拟主机文件:
<VirtualHost *:80>
ServerName www.abcxyz.org
ServerAlias abcxyz.org
WSGIScriptAlias / /var/www/abcxyz/django/abcxyz/wsgi_prod.py
Alias /static/ /var/www/abcxyz/static/
<Location "/static/">
Options -Indexes
</Location>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
据我了解,wsgi_prod.py文件应该只在服务器启动时执行一次(或者当它收到第一个请求时 - 我对此不太确定)。但在我的应用程序中,当向服务器发送请求时,它会执行多次。
它不是对所有请求执行,而是对其中一些请求执行。还有一些请求,会触发执行wsgi_prod.py只是有时会触发执行。
这是我的 wsgi_prod.py 文件:
import os
import sys
import site
import thread
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/etc/Envs/abcxyz/local/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/abcxyz/django')
sys.path.append('/var/www/abcxyz/django/abcxyz')
os.environ['DJANGO_SETTINGS_MODULE'] = 'abcxyz.settings.production'
# Activate your virtual env
activate_env=os.path.expanduser("/etc/Envs/abcxyz/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env)) …Run Code Online (Sandbox Code Playgroud) 我正在努力让 Apache 为 Django 项目提供静态文件。我的 VirtualHost 有:
Alias /static/ /home/jonathan/pragmatometer/static/
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
Run Code Online (Sandbox Code Playgroud)
但是对 /static/css/style.css 的请求是由 Django 进程提供的,而不是对 /home/jonathan/pragmatometer/static/css/style.css 的静态拉取。
我该怎么做才能让 Alias 胜过代理?我可以尝试为 /load/、/save/、/admin/ 拼凑几个 ProxyPass / ProxyPassReverse 定义,但这肯定是错误的方式。
那么正确的方法是什么?
我正在尝试将我的项目移至 docker,并且我一直在使用 alpine 变体。这是一个带有 postgres 数据库的 django 项目
这是我安装依赖项的方法:
...
ADD ./requirements.txt /srv/sites/mysite/requirements.txt
RUN echo "http://mirror.leaseweb.com/alpine/edge/testing" >>
/etc/apk/repositories
RUN apk add --no-cache --virtual .build-deps \
build-base postgresql-dev libffi-dev gcc libc-dev linux-headers bash \
geos geos-dev jpeg-dev zlib-dev \
&& pip install -r requirements.txt \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \ …Run Code Online (Sandbox Code Playgroud) 我是 Linux 新手。
我正在管理一个(Linux - Apache - mod_wsgi - Django)服务器,其中有多个 Python 安装。该站点目前正在运行,但我想找出使用哪个 Python 可执行文件来运行它。我知道这不是默认的。
另外,mod_wsgi 如何知道要使用哪个 Python 安装?该.wsgi脚本没有shebang行。
我已经使用 Debian 一年了,主要是作为我公司内部服务器的发行版。现在我正在制作一个公共电子商务网站,我计划为此目的在数据中心使用专用的 Debian 服务器。我将接受信用卡付款并将它们直接传输到银行网关,而不存储任何 CC 信息。
我将使用 Django 1.1.1、mod_wsgi、Apache2 来运行 django 和 nginx 来提供静态媒体服务。
好的,我在我的服务器上设置了 Django、nginx 和 uWSGI……问题是我通过以下命令手动启动了 uWSGI:
uwsgi -s /home/user/sites/sock/uwsgi.sock -t 10 -M -p 1 -C --pythonpath /home/user/sites/ -w mysite.django_wsgi
而且效果很好。我想做的是使用 supervisord 来控制 uWSGI 进程(启动、停止等)。我将如何做到这一点,supervisord 配置会是什么样子?
我正在运行一个使用 Django、Nginx、Gunicorn、Supervisord 和 fail2ban(只允许 ssh、http 和 https)的站点。该站点正在运行且正常运行,但有一些 nginx 错误日志条目与以下内容有关:
connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: www.example.com, request: "GET /example/url/to/get/ HTTP/1.1", upstream: "http://[::1]:8000/example/url/to/get/", host: "www.example.com"
upstream server temporarily disabled while connecting to upstream, client: x.x.x.x, server: www.example.com, request: "GET /example/url/to/get/ HTTP/1.1", upstream: "http://[::1]:8000/example/url/to/get/", host: "www.example.com"
Run Code Online (Sandbox Code Playgroud)
这是我的 nginx 配置:
upstream app_server_wsgiapp {
server localhost:8000 fail_timeout=0;
}
server {
listen 80;
server_name www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
server_name www.example.com;
listen 443 ssl;
if ($host = …Run Code Online (Sandbox Code Playgroud) django ×10
apache-2.2 ×4
mod-wsgi ×3
nginx ×3
python ×3
wsgi ×2
alpine ×1
amazon-ec2 ×1
debian ×1
docker ×1
fastcgi ×1
gunicorn ×1
linux ×1
postgresql ×1
proxy ×1
supervisord ×1
uwsgi ×1