玩龙天子 发表于 2018-11-10 13:06:05

让 nginx 支持thinkphp 的 PATH_INFO 和 URL Rewrite模式支持

usernobody;  
worker_processes1;
  
error_loglogs/error.loginfo;
  
pid      logs/nginx.pid;
  
events {
  
use epoll;
  
worker_connections1024;
  
}
  
http {
  
include       mime.types;
  
default_typeapplication/octet-stream;
  
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
  
'$status $body_bytes_sent "$http_referer" '
  
'"$http_user_agent" "$http_x_forwarded_for"';
  
access_loglogs/access.logmain;
  
sendfile      on;
  
keepalive_timeout65;
  

  
gzip on;
  
gzip_min_length1k;
  
gzip_buffers   4 16k;
  
gzip_http_version 1.0;
  
gzip_comp_level 2;
  
gzip_types       text/plain application/x-javascript text/css application/xml;
  
gzip_vary on;
  
server {
  
listen       80;
  
server_namelocalhost;
  
location / {
  
root   html;
  
indexindex.php index.html index.htm;
  
}
  
error_page   500 502 503 504/50x.html;
  
location = /50x.html {
  
root   html;
  
}
  
location ~ \.php {                   #去掉后面的$
  
root         html;
  
fastcgi_pass   127.0.0.1:9000;
  
fastcgi_indexindex.php;
  
fastcgi_split_path_info ^(.+\.php)(.*)$;                           #增加这一句
  
fastcgi_param PATH_INFO $fastcgi_path_info;                        #还有这一句
  
#####fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
  
fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name;# 这个是在配置nginx+php整合的时候就改好的$前面的是网站的主目录
  
include      fastcgi_params;
  
}
  
if (!-e $request_filename)
  
{
  
#地址作为将参数rewrite到index.php上。
  
rewrite ^/(.*)$ /index.php/$1;
  
#   若是子目录则使用下面这句,将subdir改成目录名称即可。
  
# rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
  
#    }
  
}
  
}
  
server {
  
listen       80;
  
server_names.abc.org;
  
location / {
  
root   html;
  
indexindex.html index.htm;
  
}
  
location /status {
  
stub_status on;
  
access_log   on;
  
allow 192.168.80.0/24;
  
}
  
}
  
}


页: [1]
查看完整版本: 让 nginx 支持thinkphp 的 PATH_INFO 和 URL Rewrite模式支持