腾讯云优惠券

Windows版宝塔的NGINX安装后台管理框架除首页外其它页面404错误的解决方案

人气:1,548 更新:2022-03-21
win10安装宝塔Windows面板7.5.0版本+php7+NGINX,安装 thinkphp 框架时pathinfo模式无效,这导致所有依赖 PATH_INFO的PHP框架,路由都是404。

第一步:先确定PHP版本是否开启了pathinfo,如图所示

bt-pathinfo-01.png

第二步:修改NGINX配置,主要是修改path_info的变量,修改位置如图所示,要替换的代码放在后面直接复制替换即可。

bt-pathinfo-02.png

#PHP-INFO-START 
location ~ \.php(.*)$ {
    try_files $uri =404;
    fastcgi_pass   127.0.0.1:20074;
    fastcgi_index  index.php;

    set $path_info "";
    set $real_script_name $fastcgi_script_name;
    if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
        #将文件地址赋值给变量 $real_script_name
        set $real_script_name $1;
        #将文件地址后的参数赋值给变量 $path_info
        set $path_info $2;
    }
    #配置fastcgi的一些参数
    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
    fastcgi_param SCRIPT_NAME $real_script_name;
    fastcgi_param PATH_INFO $path_info;

    include        fastcgi_params;
}
#PHP-INFO-END