最新完美解决nginx支持thinkphp的PATH_INFO,URL格式的问题
2016-07-18 11:38
716 查看
server
{
listen 80;
#listen [::]:80;
server_name www.hephp.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.hephp.com;
include n.conf;
#error_page 404 /404.html;
#include enable-php.conf;
location / {
index index.htm index.html index.php;
#访问路径的文件不存在则重写URL转交给ThinkPHP处理
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php{
#root /home/wwwroot/www.hephp.com;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
#加载Nginx默认"服务器环境变量"配置
include fastcgi.conf;
#设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
set $fastcgi_script_name2 $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
set $fastcgi_script_name2 $1;
set $path_info $2;
}
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2;
fastcgi_param SCRIPT_NAME $fastcgi_script_name2;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log off;
}
{
listen 80;
#listen [::]:80;
server_name www.hephp.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.hephp.com;
include n.conf;
#error_page 404 /404.html;
#include enable-php.conf;
location / {
index index.htm index.html index.php;
#访问路径的文件不存在则重写URL转交给ThinkPHP处理
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php{
#root /home/wwwroot/www.hephp.com;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
#加载Nginx默认"服务器环境变量"配置
include fastcgi.conf;
#设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
set $fastcgi_script_name2 $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
set $fastcgi_script_name2 $1;
set $path_info $2;
}
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2;
fastcgi_param SCRIPT_NAME $fastcgi_script_name2;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log off;
}
相关文章推荐
- Nginx配置文件详细说明
- nginx配置引发的403问题
- 查看nginx,apache,mysql,php的编译参数
- linux——Nginx安装
- 使用Nginx+Lua(OpenResty)开发高性能Web应用
- Python脚本——Nginx日志分割
- Nginx安装
- nginx配置文件
- Apache和Nginx设置伪静态(URL Rewrite)的方法
- nginx_Nchan调试
- nginx启动、开机自启动、重启、关闭
- Nginx 的 Echo 模块 —— echo-nginx-module(转)
- nginx $remote_addr 详解
- Nginx工作原理和优化、漏洞(转)
- nginx把两个不同的网站挂到同一台服务器的80端口上
- nginx prime
- ubuntu 安裝 nginx
- mac OSX, nginx 解析PHP
- CenterOS6.5(Minimal) 搭建nginx
- Nginx配置文件nginx.conf中文详解