1

I'm trying to set-up dynamic 404 pages so that I can keep the URL of the missing content, show it on the 404 page and keep my site's template consistent.

Here is my site conf:

server {
    listen       80;
    server_name  www.mysite.com;

    client_max_body_size 1024M;
    client_body_buffer_size 512M;

    rewrite ^/([a-zA-Z0-9-_]+)$ /profile.php?url=$1 last;

    root   /var/www/html/mysite;
    error_page 404 /404.php

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 1y;
        log_not_found off;
    }

    location / {
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {
        fastcgi_pass  mysite_fast_cgi;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/mysite$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }

    location = /404.php {
        internal;
    }
}

This just serves the default Nginx 404 page.

Thanks for the help in advance!

4

1 に答える 1

1

Have you tried error_page 404 = /404.php;?

Here is quotation of official nginx documentation:

If an error response is processed by a proxied server, or
a FastCGI server, and the server may return different response
codes (e.g., 200, 302, 401 or 404), it is possible to respond
with a returned code:

    error_page 404 = /404.php;
于 2012-08-09T16:55:05.207 に答える