thinkphp 3.2.3在nginx+php下的url重写配置经验

浏览:4245 发布日期:2016/05/31 分类:技术分享
上午把阿里云服务器重装了,改apache+php为nginx+php,报错404
经搜索,是rewrite规则导致。最后改为如下,ok。
供大家参考:

[root@iZ28e86crvkZ vhosts]# vi default.conf
server {
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /alidata/www/default;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;

#下面9行拷贝自网络,因没时间测试,不知道可不可以去掉。有时间的兄弟去掉测试一下,反馈一下,谢谢
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param script_FILENAME $document_root$real_script_name;
fastcgi_param script_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
include /alidata/server/nginx/conf/rewrite/default.conf;

if (!-e $request_filename) {
#下面两行重要,我的应用是部署在子目录oms下的,部署在根目录下的,需要去掉/oms
rewrite ^/oms/index.php(.*)$ /oms/index.php?s=$1 last;
rewrite ^/oms/(.*)$ /oms/index.php?s=$1 last;
break;
}
access_log /alidata/log/nginx/access/default.log;
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>