标签归档:pathinfo

nginx+php-fpm支持pathinfo

nginx配置

nginx站点配置文件如下:

server {
        listen       80;
        server_name  devkang.com;
        root  /www/devkang.com/;
        location / {
            try_files $uri $uri/ /index.php$uri?$args;
            index  index.html index.htm default.html default.htm index.php default.php;
        }
        autoindex off;
        include advanced_settings.conf;
        location ~ ^.+.php {
            fastcgi_pass   bakend; ##此处填写本机PHP的地址跟端口,根据各自情况进行设置。
            fastcgi_index  index.php;
            fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
            fastcgi_param  PATH_INFO $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_path_info;
            include        fastcgi.conf;
        }
        }
}

创建配置文件以后重启nginx。

测试

在目录下创建index.php,编辑如下代码

<?php
print_r($_SERVER);

访问地址:http://localhost/index.php/pathino或者http://localhost/pathinfo

都应该打印变量PHP_SELF的值为pathinfo即为成功。(pathinfo与url路径中的pathinfo一致即可!)

本文已经被查看625次