3

While running the django project locally, I can access my home, admin, app1, app2 directory (i.e localhost:portnum , localhost:portnum/admin , localhost:portnum/app1 , localhost:portnum/app2 )

The problem begins when I deployed the app in a server ( I used nginx and gunicorn for django deployment with the help of this guide )

Problem : - I'm unable able to access example.com/admin, example.com/app1 , example.com/app2. I'm able to access my home example.com anyway.

When I trying to access example.com/app1/ the page give an error 403 forbidden

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"

Some solutions which I tried to follow before this question::-

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;
    }
}

Thank You for trying to solve my problem.

RAM
  • 2,257
  • 2
  • 19
  • 41
Ajmal
  • 31
  • 1
  • 5

1 Answers1

1

When you use= in a location directive, it only applies for that exact path. Instead you should remove those for both of your locations and let nginx match for all prefixes.

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

 location / {
   include proxy_params;
   proxy_pass http://unix:/home/ubuntu/example_project/exampl_project.sock;
 }
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Thank you Now I got the access to example.com/admin successfully. But stiil my apps are forbidden (i.e example.com/app1 produce a forbidden error) . – Ajmal Nov 19 '18 at 19:04