1. 首先在nginx.conf里加上几行代码
location ~ \.php$ {
root /usr/local/nginx/html/admin/public;(我自己tp5的目录)
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;(默认索引文件)
fastcgi_split_path_info ^(.+\.php)(.*)$; # 这句1
fastcgi_param PATH_INFO $fastcgi_path_info; # 这句2
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; # 这句3
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 这句4
include fastcgi_params;
2. 然后在location / 下增加 这四行代码
注: 此段开启nginx的重写模块 访问时不需要添加 index.php
location / {
root /usr/local/nginx/html/admin/public;(本人自己的目录视个人情况而定)
index index.html index.htm index.php;
if (!-e $request_filename) { # 开启nginx的重写模块
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
3. 最终配置
server {
listen 80;
server_name testnginx;
location / {
root /usr/local/nginx/html/admin/public;
index index.html index.htm index.php;
if (!-e $request_filename) { # 开启nginx的重写模块
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php$ {
root /usr/local/nginx/html/admin/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED
/usr/local/nginx/html/admin/public$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME
/usr/local/nginx/html/admin/public$fastcgi_script_name;
include fastcgi_params;
}
}