The configuration of the Web-based general solution is as follows:
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; }}
In fact, it should be simpler to use the FastCGI module with a fastcgi_split_path_info directive specifically designed to solve this kind of problem, which separates the URL according to the given regular expression, 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_pass127.0.0.1:9000; Fastcgi_index index.php; #设置PATH_INFO, note that Fastcgi_split_path_info has automatically rewritten fastcgi_script_name variables, #后面不需要再改写SCRIPT_FILENAME, SCRIPT_NAME environment variables, So you must set Fastcgi_split_path_info before loading fastcgi.conf^ (. +\.php) (/.*)$; Fastcgi_param path_info $fastcgi _path_info; #加载Nginx默认"Server Environment Variables"configuration include fastcgi.conf; } }
[Turn]http://blog.csdn.net/tinico/article/details/18033573
The most perfect solution to Nginx deployment thinkphp Project