我正在尝试在特定服务器上显示自定义404页面。 404错误页面位于/www/example/html/404.php,网站根目录为/ www / example / html /
目前,任何不存在的页面都会产生此结果http://i.imgur.com/NUvZ9uG.png,并且似乎没有加载我的自定义404页面(它有一些自定义样式和菜单)。几天以来,我一直在努力使用不同的.conf设置,我现在的nginx.conf就在下面。我在Ubuntu 12,Nginx 1.1.19并使用php-fpm。
user www-data;
worker_processes 5;
error_log logs/error.log;
worker_rlimit_nofile 8192;
events {
worker_connections 4096;
}
http {
include mime.types;
include fastcgi_params;
index index.php index.html index.htm;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128;
server {
listen 80;
server_name example.com;
client_max_body_size 20M;
root /www/example/html;
access_log logs/example.access.log;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location /404.php {
internal;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
error_page 404 /404.php;
fastcgi_pass 127.0.0.1:9000;
}
location ~ /\.ht {
deny all;
}
}
答案 0 :(得分:1)
我认为您应该执行以下操作:
error_page 404 /www/example/html/404.php;
location /404.php {
return 404;
}
您的访问权限和错误日志显示了什么?
第二种选择。为“服务器”上下文定义一个自定义404页面:
server {
...
error_page 404 /www/example/html/404.php;
...
}
答案 1 :(得分:0)
您是否尝试过使用location ~ \.php$
块:
error_page 404 = /404.php;
或者
location ~ \.php$ {
error_page 404 @fallback;
}
location @fallback {
proxy_pass http://example.com/html/404.php
}