我正在尝试使用uWSGI,NGINX和主管在DO droplet上在ubuntu 16.04上部署django。
我使用
成功运行应用程序python manage.py runserver [ip]:8000
和
uwsgi --http-socket :8080 --module saleor.wsgi
当我尝试与主管一起运行应用程序时,我得到了:
502 Bad Gateway in the browser.
在ngxinx日志中我得到:从上游读取响应头时上游过早关闭连接
我的nginx conf文件:
# the upstream component nginx needs to connect to
upstream saleor {
server unix:///etc/uwsgi/saleor.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
listen 80 default_server;
server_name example.com; # IP removed from post on purpose
charset utf-8;
# max upload size
client_max_body_size 4G; # adjust to taste
access_log /webapps/saleor/saleor/logs/nginx-access.log;
error_log /webapps/saleor/saleor/logs/nginx-error.log;
# Django media
location /media {
alias /webapps/saleor/saleor/media; # your Django project's media files - amend as required
}
location /static {
alias /webapps/saleor/saleor/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass unix:///etc/uwsgi/saleor.sock;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
my saleor_uwsgi.ini文件:
[uwsgi]
die-on-term = true
http-socket = /etc/uwsgi/saleor.sock
log-format = UWSGI uwsgi "%(method) %(uri) %(proto)" %(status) %(size) %(msecs)ms [PID:%(pid):Worker-%(wid)] [RSS:%(rssM)MB]
master = true
max-requests = 100
memory-report = true
chdir = /webapps/saleor
virtualenv = /webapps
module = saleor.wsgi:application
processes = 4
static-map = /static=/app/static
chmod-socket = 666
vacuum = true
我的supervisor.conf文件
[program:saleor]
autostart=true
autorestart=true
stopsignal=QUIT
command = /usr/bin/uwsgi --ini /webapps/saleor/saleor_uwsgi.ini
stderr_logfile = /webapps/saleor/saleor/logs/supervisor_err.log
stdout_logfile = /webapps/saleor/saleor/logs/uwsgi_out.log
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8
为什么主管没有启动流程,因为我是单独启动它们的?
[编辑] 添加uwsgi日志:
[uWSGI] getting INI configuration from /webapps/saleor/saleor_uwsgi.ini
[uwsgi-static] added mapping for /static => /app/static
*** Starting uWSGI 2.0.12-debian (64bit) on [Fri Jan 26 11:50:13 2018] ***
compiled with version: 5.4.0 20160609 on 31 August 2017 21:02:04
os: Linux-4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018
nodename: srt
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /
detected binary path: /usr/bin/uwsgi-core
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /webapps/saleor
your processes number limit is 3913
your memory page size is 4096 bytes
detected max file descriptor number: 1024
building mime-types dictionary from file /etc/mime.types...552 entry found
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/saleor.sock fd 3
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 363840 bytes (355 KB) for 4 cores
*** Operational MODE: preforking ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
<击> !!!!!!!!!!!!!!警告 !!!!!!!!!!!!!! 没有加载请求插件,您将无法管理请求。 您可能需要为您选择的语言安装软件包,或者只需使用--plugin加载它。 !!!!!!!!!!!警告结束!!!!!!!!!!
spawned uWSGI master process (pid: 2336)
spawned uWSGI worker 1 (pid: 2337, cores: 1)
spawned uWSGI worker 2 (pid: 2338, cores: 1)
spawned uWSGI worker 3 (pid: 2339, cores: 1)
spawned uWSGI worker 4 (pid: 2340, cores: 1)
取得一些进展:
我添加了uwsgi-plugin-python并更新了uwsgi设置 plugins = python3。警告现在消失了。