访问某些文件类型不存在的文件,如xxx.html、xxx.log、xxx.txt等,能够显示主题自定义404内容,但是访问一个不存在的PHP、css、js等文件,还是返回nginx默认的404页面。这是怎么回事?
下面是我的配置:
nginx.conf
========
server
{
listen xx.xx.xx.xx:80;
#listen [::]:80;
server_name
xx.com www.xx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/vhosts/xx;
include typecho.conf;
location ~ [^/]\.php(/|$)
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
include pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
}
-------------------------------------------------------------------------
typecho.conf
========
location / {
index index.html index.php;
if (-e $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-e $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-e $request_filename){
rewrite (.*) /index.php;
}
}
-------------------------------------------------------------------------
pathinfo.conf
========
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
try_files $fastcgi_script_name = 404;
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/119275
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.