Domanda

i have deployed a sample django project with gunicorn on my nginx server, I need to show my own 404 page not found html page when user enters a wrong url.I tried like this in my nginx.conf file

server {
listen localhost:8899;
root /home/mulagala/Desktop/projects/28-05-2014/mysite/mysite/templates
access_log  /var/log/nginx/example.log;
error_log /var/log/nginx/example.error.log;

location / {
    proxy_pass http://127.0.0.1:8060;
}

# redirect server error pages to the static page /40x.html
#
  error_page  404              /404.html;
  location  = /404.html {
    }

# redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }


location /static/ {
    autoindex on;
    alias /home/mulagala/Desktop/projects/28-05-2014/mysite/static/;
}
} 

But when i enter a wrong url still i am getting django default message Page not found (404) , and showing all my url's.Am i need to change anything in my django project or anything else.What mistake i am doing.Any help would be appreciated

È stato utile?

Soluzione

You don't need this error_page 404 block and make sure you have proxy_intercept_errors off;. If these two conditions are met, nginx will let the application (here, Django) returns its own 404 page.

This configuration file should be fine:

server {
    listen localhost:8899;
    root /home/mulagala/Desktop/projects/28-05-2014/mysite/;
    access_log /var/log/nginx/example.log;
    error_log /var/log/nginx/example.error.log;

    location / {
        proxy_pass http://127.0.0.1:8060;
    }

    location /static/ {
        autoindex on;
        alias /home/mulagala/Desktop/projects/28-05-2014/mysite/static/;
    }
} 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top