nginx完美支持TP5的pathinfo路由模式

宝塔面板windows-5.4.0+Nginx-1.12配置(Linux请使用宝塔面板,可以直接打开配置文件,然后根据这个修改,一样的)

请完全按此顺序执行,不然我也不清楚有没有其他问题

1、通过宝塔线安装好Nginx与其它环境

2、通过宝塔面板 添加 网站 (这一步很重要,宝塔会自动配置一些文件,可以省去很多事情)

3、打开宝塔目录应该是(我的宝塔是装个在D盘,路径如下D:\BtSoft\WebSoft\nginx\conf\vhost) 注意红色部分,是conf\vhost目录下

4、打开找到对应的域名.conf文件,比如:你的网站域名是www.xxx.com,那么vhost目录下就会有一个www.xxx.com.conf文件,用记事本以外的软件打开编辑,你会看到如下的代码(软件自动生成的)

#START-SITE
server {
listen 80;
server_name www.jsq.com;
access_log logs/www.jsq.com.access.log;
root D:/wwwroot/www.jsq.com; #网站绝对路径
index index.php default.php index.html index.htm default.html default.htm;

include rewrite/www.jsq.com.conf;

#START-ERROR-PAGE
error_page 403 /403.html;
error_page 404 /404.html;
error_page 502 /502.html;
#END-ERROR-PAGE

#301-START
#301-END

#REFERER-START
#REFERER-END

#PROXY-START
#PROXY-END

#START-SSL
#END-SSL

#START-PHP
location ~ \.php$ {
root D:/wwwroot/www.jsq.com;
fastcgi_pass 127.0.0.1:4554;#后面4554 为默认端口请勿修改
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#END-PHP
}
#END-SITE

5、修改配置文件如下,红色部分是修改后的,切勿直接复制 代码增加不了颜色,看中文注释

#START-SITE
server {
listen 80;
server_name www.jqqq.com;
access_log logs/www.jqqq.com.access.log;
root E:/wwwroot/www.jqtest.com/public;
index index.php default.php index.html index.htm default.html default.htm;

#include rewrite/www.jqqq.com.conf; #注释该行,无需引用
location / { #第一部分 起始
try_files $uri $uri/ /index.php$uri;
#下面这两个if是为了能获取$_GET参数,不加则无法获取
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
} #第一部分 结束

#START-ERROR-PAGE
error_page 403 /403.html;
error_page 404 /404.html;
error_page 502 /502.html;
#END-ERROR-PAGE

#301-START
#301-END


#REFERER-START
#REFERER-END

#PROXY-START
#PROXY-END

#START-SSL
#END-SSL
location ~ /\.ht { #第二部分 起始
deny all;
} #第二部 结束

#START-PHP
location ~* \.php(.*)$ {
root E:/wwwroot/www.jqtest.com/public;
fastcgi_pass 127.0.0.1:4554;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; #第三部分 起始
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info; #第三部分 结束
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#END-PHP
}
#END-SITE

6、重启Nginx 然后看看网站是否已经可以使用路由了,并且$_GET参数也可以正常使用。

转自链接:https://blog.csdn.net/weixin_41000837/article/details/80447055

猜你喜欢

转载自www.cnblogs.com/chenweihao/p/9941220.html