Python Django应用程序,nginx和gunicorn仅显示欢迎页面,其余所有页面显示404错误

Python Django应用程序,nginx和gunicorn仅显示欢迎页面,其余所有页面显示404错误,python,django,nginx,amazon-ec2,Python,Django,Nginx,Amazon Ec2,我在nginx和gunicorn的帮助下,尝试在AmazonEC2服务器上部署一个示例django应用程序。我在nginx中添加了代理传递。在我运行服务器并访问我的IP之后,我能够查看欢迎来到django页面。但当我导航到其他一些URL时,比如admin,它显示404未找到错误 如何修复此错误 Nginx配置: upstream app { server 127.0.0.1:8000; } server { listen

我在
nginx
gunicorn
的帮助下,尝试在AmazonEC2服务器上部署一个示例django应用程序。我在
nginx
中添加了代理传递。在我运行服务器并访问我的IP之后,我能够查看欢迎来到django页面。但当我导航到其他一些URL时,比如admin,它显示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;
            }
}
您需要更改以下内容:

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页面。 我把它取了下来,然后开始工作


感谢您在评论中提到它

这些信息不足以追踪问题。Nginx配置在这里会很有帮助。假设在本地运行dev server时所有路由都有效?URL.py中的示例路由是什么样子的?请尝试删除
Try\u files
语句。404错误是什么样子的?还请尝试重新启动gunicorn服务,如果您使用debian类型的sudo systemctl restart gunicorn,请检查此项