一 環境介紹:
win10,? LNMP
?
二 錯誤描述:
訪問網站時,提示"No input file specified"錯誤.
排錯階段:
?
1. 查看nginx access日志 (access.log)
發現提示404 錯誤
?
2. 分析原因:
這時,在同目錄下創建一個txt文件,訪問就可以正常輸出了
這說明 現在nginx 訪問php 沒有輸出,意味著沒有對php文件進行解析
這樣問題就明朗了,多半和 cgi 以及 location的定義有關
?
3. 解決方案:
在對應域名的vhost配置文件中添加對php文件的解析
注: 在項目中,我們經常會用到redis,而有時我們項目出現莫名的錯誤,很可能就和redis有關,所以,我們要養成一旦項目出現錯誤, 首先排查redis , 看redis 是否可以正常連接 .?
4. 具體配置文件代碼如下:
?
server {listen 80;server_name test.kk.com;charset utf-8;access_log logs/access/test.kk.com.access.log main;error_log logs/error/test.kk.com.error.log debug;root "E:/PHP/phpstudy/WWW/Project/kk";index index.html index.htm index.php;location /favicon.ico {log_not_found off;access_log off;}location /static/original {}location /static {access_log off;}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 / {if (!-e $request_filename) {rewrite ^/comic-detail-(\d+)/ /mh-$1/ permanent;rewrite ^/comic-detail-(\d+)/(\d+)/ /mh-$1/$2/ permanent;rewrite ^/show-(\d+)-(\d+)/ /mh-$1/$2/ permanent;rewrite ^/show-(\d+)-(\d+)-(\d+)/ /mh-$1/$2-$3/ permanent;rewrite ^/mh-(\d+)/(\d+)/$ /read-comic-$1-$2/ last;rewrite ^/mh-(\d+)/(\d+)-(\d+)/$ /read-comic-$1-$2-$3/ last;rewrite "^/uploads/manhua/\d+/\d{4}-(\d{3})-(\d{2})-(\d{2})-(\d{2})-(\d+)-(.*)$" /static/comic2/$1/$2/$3/$4/$5/$6 last;rewrite ^/(.*)$ /index.php?$1 last;}}location /union/ {rewrite ^/union/(.*)$ /union/index.php?$1 last;}location ~ /\.ht {deny all;}
}
?
?
后記:
在本地配置了一個本地站 ,nginx配置文件?
看起來似乎沒有什么問題,很簡單的一個配置,但是打開該域名后,卻發現報404。
反復檢查路徑,絕對沒有任何問題啊,怎么會連html文件都報404呢,如果連html文件都報404,那絕對不是因為cgi的配置問題,肯定是和路徑有關,但是路徑檢查了很多遍了啊,看看nginx 這個網站的錯誤日志看看有沒有什么收獲吧,反復看了之后,你猜我發現了什么?
what?居然是est,我配置文件里命名寫的是test這個單詞,忽然我想起來了,靠,他把我的 ‘\test中’的 '\t'給轉義了。
在前面再加個\轉義回來,問題得以解決,這個問題真的是太容易忽略了,記錄下來