讓nginx完美支援Thinkphp的配置
阿新 • • 發佈:2019-01-31
習慣了用apache後,當第一次用nginx時,把原來的專案(thinkphp框架)部署在新伺服器上的時候,驚呆了!
所有的URL模式下都不能正常執行,甚至連css,js檔案都不能正常載入。
原因是ngibx不支援pathinfo
主要是需要配置nginx
location / { root D:/wnmp/www; index index.html index.htm; #訪問路徑的檔案不存在則重寫URL轉交給ThinkPHP處理 if ( !-e $request_filename ) { rewrite ^/(.*)$ /index.php/$1 last; break; } }
最後這部分是為了css和js 以及圖片等資源location ~ \.php/?.*$ { root D:/wnmp/www; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; #載入Nginx預設"伺服器環境變數"配置 include fastcgi_params; include fastcgi.conf; #設定PATH_INFO並改寫SCRIPT_FILENAME,SCRIPT_NAME伺服器環境變數 set $fastcgi_script_name2 $fastcgi_script_name; if ( $fastcgi_script_name ~ "^(.+\.php)(/.+)$" ) { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; }
location ~* ^.+\.(jpg|jpeg|gif|png|bmp|css|js|swf)$ {
access_log off;
root D:/wnmp/www;
break;
}