我试图build立一个404文件,它处理未知的url请求使用error_page指令,该文件即时尝试将其根目录是一个.php文件,这是在path相同的目录。
我无法弄清楚的问题是,只要我创build一个404路由,并定义它的位置似乎下载文件,而不是服务它。 为了testing我不会精神错乱,我把额外的PHP文件放在404规则之外,他们运行并返回内容,但404规则文件只是下载
我的configuration的片段是
root /var/www/itn; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { access_log off; log_not_found off; expires 1d; } error_page 404 /404.php; location = /404.php{ root /var/www/itn; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/error/html; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; include fastcgi_params; }
快速search解决schemebuild议fastcgi_intercept_errors但切换开启和closures不改变帮助,也注意到,如果我把一个假的urlwww.site.com/somecraphere它去了一个网站无法到达ERR_INVALID_RESPONSE所以我认为404规则是工作它只是不能做任何事情与文件。
所有的build议,改进和更正,赞赏
原来我不是个聪明人
没有尝试包含在location ~ \.php$
try_files $uri /404.php;
它不会执行PHP,而是会尝试以服务于图像或文档的方式提供服务。