配置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文件再末尾添加內(nèi)容 引入文件;
單文件多配置添加: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文件
添加內(nèi)容:127.0.0.1 www.common.com
1、linux一般處于/etc/hosts下修改完成重啟服務、網(wǎng)絡即可
centos7 重啟網(wǎng)絡:service network restart
centos8 重啟網(wǎng)絡:nmcli c reload
2、window 系統(tǒng)一般處于C:\Windows\System32\drivers\etc\下修改后重啟服務