Reputation: 1659
I tried to deploy a sample django application in amazon ec2 server with the help of nginx
and gunicorn
. I added proxy pass in nginx
. After I run the server and accessing my IP I was able to view the welcome to django page. But when I navigate to some other urls, say admin its shows 404 not found error.
How to fix this error.
Nginx config:
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;
}
}
Upvotes: 1
Views: 1078
Reputation: 1659
The problem was with the line
try_files $uri $uri/ =404;
This line is causing every url except the main url to route to 404 page. I removed it and hence working.
Thanks to @Richard Smith for mentioning it in the comment
Upvotes: 2
Reputation: 618
You need change this:
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;
}
For this:
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;
}
Upvotes: 2