如何将新的django应用添加到已部署的django项目中(使用nginx,gunicorn)?

时间:2018-11-17 18:44:49

标签: django nginx amazon-ec2 gunicorn

在本地运行django项目时,我可以访问我的主目录,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;
    }
}

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

1 个答案:

答案 0 :(得分: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;
 }