配置pathinfo模式, 隐藏index.php、配置多站点,更改nginx.conf文件
1、修改nginx.conf配置pathinfo模式、正则匹配.php后面的pathinfo部分
原配置
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
改为
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
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;
include fastcgi_params;
}
2、修改nginx.conf隐藏index.php,
添加
if (!-e $request_filename) {
rewrite ^(.*)$ /public/index.php?s=/$1 last;
break;
}
到
location / {
index index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /public/index.php?s=/$1 last;
break;
}
}
注意:/public/index.php,如果站点项目指向index.php目录,则去掉/public
3、配置多站点,支持pathinfo模式及隐藏index.php文件
1、打开nginx.conf文件再末尾添加内容 引入文件;
单文件多配置添加:include vhosts.conf;
多文件单配置添加:include *.conf;
2、打开vhosts.conf站点配置,记住路径必须是正斜线。
server {
listen 80;
server_name www.lllanpl.com ;
root /usr/local/server/www/lllanpl;
location / {
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php$1 last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $1;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
3、修改hosts文件
添加内容:127.0.0.1 www.common.com
1、linux一般处于/etc/hosts下修改完成重启服务、网络即可
centos7 重启网络:service network restart
centos8 重启网络:nmcli c reload
2、window 系统一般处于C:\Windows\System32\drivers\etc\下修改后重启服务