我是nginx的新手。
我已经配置了nginx,gunicorn和django。
当我启动nginx时,它给出一个错误,因为,404 Not Found nginx/1.1.19
因为它没有指向django。
现在我需要在conf文件中使用location或root将nginx指向django(使用gunicorn作为中间件)。
谁能告诉我怎么向django指出nginx。
谢谢
发布于 2013-12-08 17:02:44
我有很多应用都是这样运行的:
server {
# listen, statics, media, etc
location / {
proxy_pass http://127.0.0.1:8000; # Gunicorn Server
}
}发布于 2013-12-08 17:06:52
首先,您需要实际运行gunicorn进程。手动完成此操作,最好使用supervisord等进程管理工具。以下是在django项目上运行gunicorn进程的示例supervisord脚本:
[program:example]
user=ubuntu
group=ubuntu
directory=/home/ubuntu/dev/example
command=python manage.py run_gunicorn -c gunicorn_config.py
autostart=true
autorestart=true
redirect_stderr=True然后你需要一个合适的nginx conf。下面是一个基于在生产环境中运行的站点的最小示例:
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
server_name example.com;
location / {
proxy_pass http://localhost:8000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# use this if you're serving static assets locally
location /static/ { # make sure this is your STATIC_ROOT
alias /home/ubuntu/dev/example/static/;
access_log off;
}
}https://stackoverflow.com/questions/20450839
复制相似问题