【问题标题】:how to add new django app to deployed django project (using nginx,gunicorn)?如何将新的 django 应用程序添加到已部署的 django 项目(使用 nginx、gunicorn)?
【发布时间】:2019-04-20 14:49:36
【问题描述】:

在本地运行 django 项目时,我可以访问我的 home、admin、app1、app2 目录(即 localhost:portnum , localhost:portnum/admin , localhost:portnum/app1 , localhost:portnum/app2)

当我在服务器中部署应用程序时问题就开始了(我在guide 的帮助下使用 nginx 和 gunicorn 进行 django 部署)

问题:- 我无法访问 example.com/admin、example.com/app1、example.com/app2。 无论如何,我都可以访问我的主页 example.com。

当我尝试访问 example.com/app1/ 页面时出现错误 403 禁止

2018/11/17 18:00:55 [error] 28459#28459: *8 directory index of "/home/ubuntu/project/app/" is forbidden, client: 172.68.146.88, server: example.com, request: "GET /events/ HTTP/1.1", host: "www.example.com"
2018/11/17 18:00:58 [error] 28459#28459: *13 open() "/usr/share/nginx/html/app" failed (2: No such file or directory), client: 172.68.146.10, server: example.com, request: "GET /events HTTP/1.1", host: "www.example.com"

我在这个问题之前尝试遵循的一些解决方案::-

server {       
    listen 80;
    listen     443;

    ssl        on;
    ssl_certificate         /home/ubuntu/certs/cert.pem;
    ssl_certificate_key     /home/ubuntu/certs/cert.key;    
    server_name example.com;

    location = /favicon.ico {
        access_log off;
        log_not_found off;
    } 

    location = /static/ {
        root /home/ubuntu/example_project/app1;    
    }

    location = / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/example_project/exampl_project.sock;
    }
}

感谢您尝试解决我的问题。

【问题讨论】:

  • 你需要显示你的nginx配置。
  • @DanielRoseman 用我的 nginx 配置更新了我的问题

标签: django nginx amazon-ec2 gunicorn


【解决方案1】:

当您在位置指令中使用= 时,它仅适用于该确切路径。相反,您应该删除两个位置的那些,并让 nginx 匹配所有前缀。

 location /static/ {
   root /home/ubuntu/example_project/app1;    
 }

 location / {
   include proxy_params;
   proxy_pass http://unix:/home/ubuntu/example_project/exampl_project.sock;
 }

【讨论】:

  • 谢谢 现在我成功获得了对 example.com/admin 的访问权限。但是我的应用程序仍然被禁止(即 example.com/app1 产生禁止错误)。
猜你喜欢
  • 2013-12-08
  • 2015-08-05
  • 1970-01-01
  • 2019-09-19
  • 2021-11-07
  • 2016-08-06
  • 2020-12-26
  • 2016-11-03
  • 1970-01-01
相关资源
最近更新 更多