我尝试在nginx
和gunicorn
的帮助下在amazon ec2服务器中部署示例django应用程序。我在nginx
添加了代理传递。在我运行服务器并访问我的IP后,我能够查看欢迎来到django页面。但是当我导航到其他一些网址时,请说管理员显示404找不到错误。
如何解决此错误。
Nginx配置:
upstream app {
server 127.0.0.1:8000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
server_name IP;
location /static/ {
root /home/ubuntu/workspace/business;
}
location / {
proxy_pass http://app;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
答案 0 :(得分:1)
你需要改变这个:
location / {
proxy_pass http://app;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
为此:
location / {
proxy_pass http://gunicorn:8888; #use your gunicorn port
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
答案 1 :(得分:0)