I have a server (nginx) which is routing some urls to static directories, and others to a web.py wsgi app. The server’s config also defines a 404 page, which is displayed when somebody tries to visit a nonexistant file within a static directory.
However, sometimes a user will visit a url which nginx passes to python, and only then do I realize it should 404. At this point web.py has no problem returning a custom error page along with the correct status code; the problem is that I want it to return the same 404 page as the server does for pages that aren’t sent to python. Currently python is manually reading and printing the 404.html file, but that seems very inefficient.
So, is there any way for python to tell the server to display its own 404 page?
Here is my current nginx.conf, with commented lines removed.
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name light.info;
root /www/example.com/html;
index index.html;
location /s/ {}
location /error/ {}
location / {
fastcgi_pass 127.0.0.1:9001;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param REMOTE_ADDR $remote_addr;
}
error_page 404 /error/404.html;
error_page 403 /error/403.html;
error_page 500 502 503 504 /error/50x.html;
}
}
You aren’t going to have python tell nginx what to do per se, you’re going to have nginx intercept the 404’s.
uwsgi_intercept_errors on;is what you are looking for I think assuming you’re usinguwsgi. It would be helpful if you could post your current configuration…