当前位置:Gxlcms > PHP教程 > Nginx系列(七.nginx支持pathinfo)

Nginx系列(七.nginx支持pathinfo)

时间:2021-07-01 10:21:17 帮助过:30人阅读

一、通过rewrite方式代替php中的PATH_INFO (仅支持Thinkphp)

location / {
    if (!-e$request_filename){
        rewrite ^/(.*)$ /index.php?s=/$1 last;
    }
}

二、nginx配置文件中设置PATH_INFO值

location ~ \.php {
    root /web/www/thinkphp;
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9000;
    include      fastcgi_params;

    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;
}

建议关闭 cgi.fix_pathinfo 选项

三、nginx自带pathinfo支持 (新版本)

location~ [^/]\.php(/|$) {
        root /web/www/thinkphp;
        fastcgi_index index.php;
        fastcgi_pass127.0.0.1:9000;
        include      fastcgi_params;

        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}

需要开启 cgi.fix_pathinfo 选项

四. 隐藏index.php文件

location / {
    if (!-e$request_filename){
        rewrite ^/(.*)$ /index.php/$1 last;
    }
}

五.nginx 官方指导

http://wiki.nginx.org/PHPFcgiExample

以上就介绍了Nginx系列(七.nginx支持pathinfo),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行