Nginx series (seven.nginx supports pathinfo)

WBOY
Release: 2016-08-08 09:24:42
Original
1007 people have browsed it

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

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

二、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; }
Copy after login

建议关闭 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; }
Copy after login

需要开启 cgi.fix_pathinfo 选项

四. 隐藏index.php文件

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

五.nginx 官方指导

http://wiki.nginx.org/PHPFcgiExample

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!