Apache Nginx自定义错误\页面未使用指定页面?

Apache Nginx自定义错误\页面未使用指定页面?,apache,ubuntu,nginx,php,Apache,Ubuntu,Nginx,Php,我正在尝试在特定服务器上显示一个自定义404页面。404错误页面位于/www/example/html/404.php,网站根目录为/www/example/html/ 目前,任何不存在的页面都会产生这个结果,并且似乎没有加载我的自定义404页面(它有一些自定义样式和菜单)。几天来,我一直在用不同的.conf设置来解决这个问题,下面是我当前的nginx.conf。我在Ubuntu 12,Nginx 1.1.19上,使用php fpm user www-data; worker_pro

我正在尝试在特定服务器上显示一个自定义404页面。404错误页面位于/www/example/html/404.php,网站根目录为/www/example/html/

目前,任何不存在的页面都会产生这个结果,并且似乎没有加载我的自定义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;
            }
    }

我认为你应该做以下几点:

error_page 404 /www/example/html/404.php;

location /404.php {
  return 404;
}
您的访问和错误日志显示了什么

第二种选择。为“服务器”上下文中的所有内容定义自定义404页面:


您是否尝试在
位置~\.php$
块中使用:

error_page 404 = /404.php;


最近的访问日志-仍然没有加载正确的错误页。我把“error_page”代码放在“PHP”块中,它应该放在“/”块中吗?如果您需要做的只是在404上显示一个特定的自定义页面,请执行以下操作:服务器{…error_page 404=/www/example/html/404.PHP;…}。在解决问题时,请评论每个“location”块。然后尝试访问一个不存在的资源。您应该会看到自定义错误页面。顺便说一句,请确保nginx守护程序对“404.php”文件具有适当的权限。proxy_pass失败并出现错误“proxy_pass”可能在正则表达式给定的位置、命名位置、if语句或/etc/nginx/nginx.conf:181中的“limit_except”块中没有URI部分
error_page 404 = /404.php;
location ~ \.php$ {
    error_page 404 @fallback;
}

location @fallback {
    proxy_pass http://example.com/html/404.php
}