2016-12-03处理:
首先,是盯着屏幕的你最需要的正解:
server {
...
location / {
index index.htm index.html index.php;
#如果文件不存在则尝试TP解析
try_files $uri /index.php$uri;
}
location ~ .+.php($|/) {
root /var/www/html/website;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#设置PATH_INFO,注意fastcgi_split_path_info已经自动改写了fastcgi_script_name变量,
#后面不需要再改写SCRIPT_FILENAME,SCRIPT_NAME环境变量,所以必须在加载fastcgi.conf之前设置
fastcgi_split_path_info ^(.+.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
#加载Nginx默认"服务器环境变量"配置
include fastcgi_params;#原来是:include fastcgi.conf; 但是nginx v1.4.6 将 fastcgi.conf改为fastcgi_params
}
}
然后是故事的开始:
问题来了,SO百度一下你会看到一个ThinkPHP牛逼哄哄的帖子:老朱亲自写的,最完美ThinkPHP Nginx 配置文件,
他提供的解决方案如下:
server {
listen 80;
server_name thinkphp.lo;
root /var/www;
index index.html index.htm index.php;
error_page 404 /404.html;
location = /404.html {
return 404 'Sorry, File not Found!';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html; # windows用户替换这个目录
}
location / {
try_files $uri @rewrite;
}
location @rewrite {
set $static 0;
if ($uri ~ .(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css.map|min.map)$) {
set $static 1;
}
if ($static = 0) {
rewrite ^/(.*)$ /index.php?s=/$1;
}
}
location ~ /Uploads/.*.php$ {
deny all;
}
location ~ .php/ {
if ($request_uri ~ ^(.+.php)(/.+?)($|?)) { }
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_NAME $1;
fastcgi_param PATH_INFO $2;
fastcgi_param SCRIPT_FILENAME $document_root$1;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
这个确实可以解决404的问题,但是也存在几个问题:
1、当你的站点放在二级目录时,无法访问(没试过不带php的URL)
2、页面404时,nginx好像进入了死循环,页面一直再转...
于是乎Google,得到了正解!...好故事就这样结束了,no,
最终我没有选择nginx+thinkphp因为速度比apache+thinkphp慢,不知为毛,就大神指点..
支付宝打赏
微信打赏