這篇文章主要介紹了ThinkPHP中nginx配置有哪些坑,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
東山網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)公司!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)公司2013年開(kāi)創(chuàng)至今到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)公司。
THINKPHP 的 NGINX 配置踩坑
今天在用一個(gè)以 tp 為基礎(chǔ)的快速開(kāi)發(fā)框架時(shí)遇到一些問(wèn)題:
nginx 報(bào)錯(cuò)截圖
為了方便說(shuō)明進(jìn)行手動(dòng)換行
// 處理時(shí)重寫或內(nèi)部重定向循環(huán) 2019/11/11 11:16:06 [error] 15164#15432: *1 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index/user/index.html", client: 127.0.0.1, server: xxxxx, request: "GET /index/user/index.html HTTP/1.1", host: "xxxxx", referrer: "xxxxx"
錯(cuò)誤配置
參考 larvael 配置
server { . . . location / { try_files $uri $uri/ /index.php?$query_string; } . . . location ~ \.php$ { fastcgi_pass127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } . . . }
發(fā)現(xiàn)所有路徑都一樣,都是首頁(yè)效果
初步判斷 nginx 重寫規(guī)則有問(wèn)題
# 路徑 / 開(kāi)頭之后都走這個(gè)匹配 # 如 /index /index/user location / { # $uri 本地有就返回,或者$uri/ 本地有目錄就返回,或者走后面的重寫 # 本地是指在網(wǎng)站根目錄下,如 當(dāng) $uri=index 就是看根目錄下面有 index 文件或者 index/ 目錄 try_files $uri $uri/ /index.php?$query_string; }
開(kāi)始報(bào)錯(cuò)
解決問(wèn)題
網(wǎng)上查詢后 tp5 的配置應(yīng)為
location / { try_files $uri $uri/ /index.php$uri; }
改后,發(fā)現(xiàn)問(wèn)題沒(méi)解決;對(duì)比配置發(fā)現(xiàn)
# location ~ \.php$ 改成 location ~ \.php(.*)$ 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; }
解決,完整配置
server { listen 80; server_name xxxxxxx ; root www; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; charset utf-8; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php$uri; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; 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; } location ~ /\.(?!well-known).* { deny all; } }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“ThinkPHP中nginx配置有哪些坑”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!