1 sudo cd /etc/nginx/; 2 sudo vi fastcgi_params;
1.URL重寫php
若是你的url參數不是用?xxx傳遞,而是自定義的,好比用/xx/xx/xx的方式傳遞,那麼在nginx下就要開啓pathinfohtml
典型配置:nginx
1 location ~ \.php$ { 2 root html; 3 fastcgi_pass 127.0.0.1:9000; 4 fastcgi_index index.php; 5 fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name; 6 include fastcgi_params; 7 }
修改1,6兩行,支持pathinfodom
1 location ~ \.php(.*)$ { # 正則匹配.php後的pathinfo部分 2 root html; 3 fastcgi_pass 127.0.0.1:9000; 4 fastcgi_index index.php; 5 fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name; 6 fastcgi_param PATH_INFO $1; # 把pathinfo部分賦給PATH_INFO變量 7 include fastcgi_params; 8 }
2.當URL重寫後,好比訪問xxx/index.php/xxx/xxx 會空白,而用?方式訪問則正常url
a.修改fastcgi_params文件spa
sudo cd /etc/nginx/;
sudo vi fastcgi_params;
配置文件內容:code
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #這行沒有就添加,有了就改爲這樣子
b.修改nginx配置文件htm
location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 新增
include fastcgi_params; # 新增
}
3.隱藏入口文件blog
a.若是代碼就在域名指向的根目錄下,則ip
location / { // …..省略部分代碼 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } }
b.若是代碼在域名指向的下級目錄下,則
#youdomain 是所在目錄的名稱。好比域名根目錄爲/var/www/html 代碼所在目錄爲/var/www/html/wave/project,則此處youdomain均替換爲wave/projetc
location /youdomain/ { if (!-e $request_filename){ rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last; } }
===