第一次安装nginx,安装完成后发现thinkphp无法运行。查阅相关资料后通过以下方式解决:
- 配置nginx pathinfo支持:
原始配置完成后:
#location ~ \.php$ {
# root E:/www;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME E:/www$fastcgi_script_name;
# fastcgi_param PATH_INFO E:/www$fastcgi_script_name;# include fastcgi_params;
#}
增加pathinfo后的配置结果:
location ~ \.php($|/) {
rootE:/www;set $script $uri;set $path_info "";if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;set $path_info $2;
}
fastcgi_pass 127.0.0.1:9000;include fastcgi_params;fastcgi_param PATH_INFO $path_info;fastcgi_param SCRIPT_FILENAME E:/www$script;fastcgi_param SCRIPT_NAME $script;
}
- 添加thinkphp隐藏index.php支持:
如果入口文件在子目录中则为:
location / {
root E:/www;
index index.html index.php index.htm;
if (!-e $request_filename) {
rewrite ^/子目录/(.*)$ /子目录/index.php?s=$1 last;
break;
}
}
如果入口文件在web目录中为:
location / {
root E:/www;
index index.html index.php index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
打完收工