[英]gunicorn, nginx, and using port 80 for running a django web application
我在Web服务器上安装了django,nginx和gunicorn。
Nginx在80端口监听Gunicorn在8000端口运行django项目
这很好。 如果我访问www.mysite.com:8000/myapp/,django应用程序就会出现。 但是,如果我希望用户访问www.mysite.com/myapp/来查看django应用程序怎么办? 我不认为摆脱Nginx并不是答案,我希望我错过了一些可以应用的配置调整。
任何建议表示赞赏。
您可以使用以下配置,因此可以正常在端口80上访问您的网站:
这是您的nginx配置文件, sudo vim /etc/nginx/sites-available/django
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 250M;
server_name _;
keepalive_timeout 15;
# Your Django project's media files - amend as required
location /media {
alias /home/xxx/yourdjangoproject/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/xxx/yourdjangoproject/static;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
并将gunicorn配置为
description "Gunicorn daemon for Django project"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
# If the process quits unexpectadly trigger a respawn
respawn
setuid yourdjangousernameonlinux
setgid yourdjangousernameonlinux
chdir /home/xxx/yourdjangoproject
exec gunicorn \
--name=yourdjangoproject \
--pythonpath=yourdjangoproject \
--bind=0.0.0.0:9000 \
--config /etc/gunicorn.d/gunicorn.py \
yourdjangoproject.wsgi:application
不,摆脱nginx绝对不是答案。 答案是遵循非常好的文档 ,将nginx配置为gunicorn的反向代理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.