Nginx系列(七.nginx支持pathinfo)

WBOY
Libérer: 2016-08-08 09:24:42
original
1063 Les gens l'ont consulté

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

<code>location / {
    <span>if</span> (!<span>-e</span><span>$request_filename</span>){
        rewrite ^/(.*)$ /index.php?s=/<span>$1</span> last;
    }
}</code>
Copier après la connexion

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

<code>location ~ \.php {
    root /web/www/thinkphp;
    fastcgi_index index.php;
    fastcgi_pass <span>127.0</span>.<span>0.1</span>:<span>9000</span>;
    include      fastcgi_params;

    <span>set</span><span>$path_info</span><span>""</span>;
    <span>set</span><span>$real_script_name</span><span>$fastcgi_script_name</span>;
    <span>if</span> (<span>$fastcgi_script_name</span> ~ <span>"^(.+?\.php)(/.+)$"</span>) {
        <span>set</span><span>$real_script_name</span><span>$1</span>;
        <span>set</span><span>$path_info</span><span>$2</span>;
    }

    fastcgi_param SCRIPT_FILENAME <span>$document_root</span><span>$real_script_name</span>;
    fastcgi_param SCRIPT_NAME <span>$real_script_name</span>;
    fastcgi_param PATH_INFO <span>$path_info</span>;
}</code>
Copier après la connexion

建议关闭 cgi.fix_pathinfo 选项

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

<code><span>location</span><span>~ [^/]\.php(/|$)</span> {
        <span>root</span> /web/www/thinkphp;
        <span>fastcgi_index</span> index.php;
        <span>fastcgi_pass</span><span>127.0.0.1:9000</span>;
        <span>include</span>      fastcgi_params;

        <span>fastcgi_split_path_info</span><span> ^(.+?\.php)(/.*)$</span>;
        <span>fastcgi_param</span> SCRIPT_FILENAME <span>$document_root</span><span>$fastcgi_script_name</span>;
        <span>fastcgi_param</span> SCRIPT_NAME <span>$fastcgi_script_name</span>;
        <span>fastcgi_param</span> PATH_INFO <span>$fastcgi_path_info</span>;
        <span>fastcgi_param</span> PATH_TRANSLATED <span>$document_root</span><span>$fastcgi_path_info</span>;
}</code>
Copier après la connexion

需要开启 cgi.fix_pathinfo 选项

四. 隐藏index.php文件

<code>location / {
    <span>if</span> (!<span>-e</span><span>$request_filename</span>){
        rewrite ^/(.*)$ /index.php/<span>$1</span> last;
    }
}</code>
Copier après la connexion

五.nginx 官方指导

http://wiki.nginx.org/PHPFcgiExample

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

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal