【发布时间】:2012-08-06 19:27:03
【问题描述】:
我正在尝试设置动态 404 页面,以便我可以保留丢失内容的 URL,在 404 页面上显示它并保持我网站的模板一致。
这是我的网站配置:
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;
}
}
这只是提供默认的 Nginx 404 页面。
提前感谢您的帮助!
【问题讨论】:
-
您忘记了 /404.php 位置中的 proxy_pass
-
我只是尝试了各种设置,但似乎没有任何效果。我厌倦了proxy_pass mysite.com/404.php、mysite_fast_cgi,我还尝试了.php$ location 块中的fastcgi_pass 设置。
标签: php nginx rewrite http-status-code-404