設定 nginx 支援 thinkPHP 的 pathinfo 模式
阿新 • • 發佈:2019-02-19
在 nginx 下面用 ThinkPHP 做開發,每次輸入 類似 /test/tp/index.php/Index/index 的 URI , 提示沒有找到該頁
在網上搜了一下,原來 nginx 原來不支援 pathinfo 模式,需要自己配置
在配置檔案的 server 塊中,加入以下內容
# ThinkPHP 的 pathinfo 支援 -------------- BEGIN location /test/tp/ { index index.php; if (!-e $request_filename) { rewrite ^/test/tp/(.*)$ /test/tp/index.php/$1 last; break; } } location ~ .+\.php($|/) { set $script $uri; set $path_info "/"; if ($uri ~ "^(.+\.php)(/.+)") { set $script $1; set $path_info $2; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php?IF_REWRITE=1; include fastcgi_params; fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root/$script; fastcgi_param SCRIPT_NAME $script; } # ThinkPHP 的 pathinfo 支援 -------------- END
其中 /test/tp/ 是我專案的路徑
儲存配置之後,重啟 nginx ,配置成功
直接支援類似於 /Index.html 這樣的偽靜態模式