【发布时间】:2018-04-15 09:20:57
【问题描述】:
尝试在 Ubuntu 16.04 上通过 uwsgi 和 nginx 运行 django 应用程序“mysite”,但是当我启动 uwsgi 并检查我的浏览器时,它只是挂起。
我将 django 上游套接字设置为端口 8002 和 nginx 以侦听 8003。在浏览器中,我在运行 uwsgi 之前访问 192.168.0.17:8003 并抛出预期的 502,所以我启动 uwsgi
uwsgi --http :8002 --module mysite.wsgi --logto /tmp/uwsgi.log --master
当我在浏览器中重新加载时,8003 现在挂起。我查看了/var/log/nginx/error.log,但它是空白的(access.log 也是如此)。
这里是 nginx 配置,符号链接到 /etc/nginx/sites-enabled:
sudo nano /etc/nginx/sites-available/mysite_nginx.conf
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8002; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8003;
# the domain name it will serve for
server_name 192.168.0.17; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/myusername/uwsgi-tutorial/mysite/media; # your Django project's media files - amend as required
}
location /static {
alias /home/myusername/uwsgi-tutorial/mysite/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/myusername/uwsgi-tutorial/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}
我知道 Django 正在运行,因为在我的应用程序的 settings.py 我有 ALLOWED_HOSTS = ['192.168.0.17','localhost','127.0.0.1'] 并且当我在浏览器中访问端口 8002 时,我得到了 django “恭喜!”页。当我从 ALLOWED_HOSTS 中删除 192.168.0.17 时,django 仍然从 localhost 或 127.0.0.1 在那台机器上运行,所以这似乎与 ngnix 和 uwsgi 之间的通信方式有关。
有什么想法吗??
【问题讨论】:
-
nginx 错误日志是怎么说的?
标签: django nginx ubuntu-16.04 uwsgi