nginx:如何使nginx指向django
我是nginx的新手 我已经配置了nginx、gunicorn和django 当我启动nginx时,它会给出一个错误, 404找不到 nginx/1.1.19 因为它没有指向django 现在我需要在conf文件中使用location或root将nginx指向django(使用gunicorn作为中间件) 有人能告诉我如何向django指出nginx吗nginx:如何使nginx指向django,django,nginx,Django,Nginx,我是nginx的新手 我已经配置了nginx、gunicorn和django 当我启动nginx时,它会给出一个错误, 404找不到 nginx/1.1.19 因为它没有指向django 现在我需要在conf文件中使用location或root将nginx指向django(使用gunicorn作为中间件) 有人能告诉我如何向django指出nginx吗 谢谢我有很多应用程序都是这样运行的: server { # listen, statics, media, etc locat
谢谢我有很多应用程序都是这样运行的:
server {
# listen, statics, media, etc
location / {
proxy_pass http://127.0.0.1:8000; # Gunicorn Server
}
}
首先,您需要实际运行gunicorn进程。可以手动执行此操作,也可以理想地使用流程管理工具,例如。下面是一个示例supervisord脚本,它在django项目上运行gunicorn进程:
[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配置。下面是一个基于生产中运行的站点的最小示例:
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;
}
}
我需要使用location或root将nginx指向django。请在这方面给我建议。您不需要设置gunicorn以在端口8080上运行您这里的nginx配置吗?