首页 > 代码库 > nginx 配置文件 PATHINFO重写规则
nginx 配置文件 PATHINFO重写规则
user www www;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 2048;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log logs/access.log main;
sendfile on;
fastcgi_intercept_errors on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name *.newfangzhu.com newfangzhu.com;
#charset utf-8;
# include drop_sql.conf;
access_log logs/host.access.log main;
location / {
root /home/www/web/new_fangzhu;
index index.html index.htm index.php;
}
#error_page 404 =http://www.fangzhur.com/error/error.html
error_page 500 502 503 504 404 /error.html;
location = /error.html {
root /home/www/web/new_fangzhu/error;
}
include /usr/local/nginx/conf/fangzhu.conf;
location ~ \.php$ {
root /home/www/web/new_fangzhu;
fastcgi_pass 127.0.0.1:8000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name test.com;
access_log logs/host.access.log main;
location / {
root /home/www/web/Test1/Web;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ .+\.php($|/) {
root /home/www/web/Test1/Web;
set $script $uri;
set $path_info "/";
fastcgi_pass 127.0.0.1:8000;
#fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
#定义变量 $path_info ,用于存放pathinfo信息
set $path_info "";
#定义变量 $real_script_name,用于存放真实地址
set $real_script_name $fastcgi_script_name;
#如果地址与引号内的正则表达式匹配
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
#将文件地址赋值给变量 $real_script_name
set $real_script_name $1;
#将文件地址后的参数赋值给变量 $path_info
set $path_info $2;
}
#配置fastcgi的一些参数
#fastcgi_index index.php?IF_REWRITE=1;
#include fastcgi_params.conf;
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
}