One, the ordinary way
server {... location/{index index.htm index.html index.php; #访问路径的文件不存在则重写URL转交给ThinkPHP处理 if (!-e $request _filename) {rewrite ^/(. *) $/index.php/$1 last; Break }} location ~ \.php/?. *$ {root/var/www/html/website; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; #加载Nginx默认 "Server environment variables" configuration include fastcgi.conf; #设置PATH_INFO并改写SCRIPT_FILENAME, SCRIPT_NAME server environment variable set $fastcgi _script_name2 $fastcgi _script_name; if ($fastcgi _script_name ~ "^ (. +\.php) (/.+) $") {set $fastcgi _script_name2 $; Set $path _info; } fastcgi_param path_info $path _info; Fastcgi_param script_filename $document _root$fastcgi_script_name2; Fastcgi_param script_name $fastcgi _script_name2; }}
Second, in fact, should be used in a simpler way, the FastCGI module comes with a fastcgi_split_path_info directive specifically designed to solve this kind of problem, the directive will be based on the given regular expression to separate the URL, thus extracting the script name and path info information, Using this directive avoids using the IF statement, which is simpler to configure.
There is also a simpler way to determine if a file exists, using the try_files directive.
server {... Location/{ index index.htm index.html index.php; #如果文件不存在则尝试TP解析 try_files $uri /index.php$uri; } Location ~. +\.php ($|/) { root /var/www/html/website; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; #设置PATH_INFO, note that Fastcgi_split_path_info has automatically rewritten the fastcgi_script_name variable, #后面不需要再改写SCRIPT_FILENAME, Script_ The name environment variable, so you must set fastcgi_split_path_info ^ (. +\.php) (/.*) $ before loading fastcgi.conf; Fastcgi_param path_info $fastcgi _path_info; #加载Nginx默认 "Server environment variables" configuration include fastcgi.conf; }}
http://m.blog.csdn.net/article/details?id=18033573
Two configurations of the thinkphp Nginx rewrite