1. 程式人生 > >thinkphp3.2 nginx環境 隱藏 index.php

thinkphp3.2 nginx環境 隱藏 index.php

首先config.php中  URL_MODEL = 2   

VHOST  loaction / {

新增  try_files $uri $uri/ /index.php?s=$uri&$args;

}

意思是:如果第一個$uri不存在,就訪問$uri/;如果$uri/還不存在,訪問/index.php?s=$uri&$args。可以後面跟很多個。

?

try_files從字面上理解就是嘗試檔案,再結合環境理解就是“嘗試讀取檔案”,那他想讀取什麼檔案呢,

答:讀取靜態檔案

$uri  這個是nginx的一個變數,存放著使用者訪問的地址,

比如:http://www.xxx.com/index.html, 那麼$uri就是 /index.html

$uri/ 代表訪問的是一個目錄,比如:http://www.xxx.com/hello/test/    ,那麼$uri/就是 /hello/test/

完整的解釋就是:try_files 去嘗試到網站目錄讀取使用者訪問的檔案,如果第一個變數存在,就直接返回;

不存在繼續讀取第二個變數,如果存在,直接返回;不存在直接跳轉到第三個引數上。

再例如:

?

1

try_files $uri = 404

什麼意思呢?uri不能成功訪問,那好,那就給你個404吧。

server {         listen       80;         server_name  www.search.com ;         root   "F:\PHPTutorial\WWW\CRM-Search\Public";         location / {         try_files $uri $uri/ /index.php?s=$uri&$args;

            index index.php;             #autoindex  on;         }         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;             fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;             include        fastcgi_params;         } }