![](/img/trans.png)
[英]Use Docker, Gunicorn, Nginx in django development environment but can only see nginx welcome page?
[英]Django application with nginx and gunicorn only showing welcome page rest all pages showing 404 error
我尝试在nginx
和gunicorn
的帮助下在Amazon ec2服务器中部署一个示例django应用程序。 我在nginx
添加了代理密码。 运行服务器并访问我的IP后,我可以查看django的欢迎页面。 但是,当我导航到其他一些URL时,说admin其显示404 not found错误。
如何解决此错误。
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;
}
}
您需要更改此:
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;
}
问题出在生产线上
try_files $uri $uri/ =404;
此行导致除主URL之外的每个URL都路由到404页。 我将其删除,因此可以正常工作。
感谢@Richard Smith在评论中提及它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.