Nginx的設定檔server塊裡面有對PHP檔案的識別和轉寄。
location ~ [^/]\.php(/|$){ # comment try_files $uri =404; to enable pathinfo try_files $uri =404; #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; #include pathinfo.conf;}
這段正則可以識別PHP結尾的檔案。
但是為什麼我訪問`http://123.123.123.123/abc.abc.acb/index.php'
就出現了502錯誤?
如果我把上面的正則重複一遍就好了。
location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ [^/]\.php(/|$){ # comment try_files $uri =404; to enable pathinfo try_files $uri =404; #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; #include pathinfo.conf;}
這個樣子,就能正常訪問到PHP。這個是為什嗎?
回複內容:
Nginx的設定檔server塊裡面有對PHP檔案的識別和轉寄。
location ~ [^/]\.php(/|$){ # comment try_files $uri =404; to enable pathinfo try_files $uri =404; #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; #include pathinfo.conf;}
這段正則可以識別PHP結尾的檔案。
但是為什麼我訪問`http://123.123.123.123/abc.abc.acb/index.php'
就出現了502錯誤?
如果我把上面的正則重複一遍就好了。
location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ [^/]\.php(/|$){ # comment try_files $uri =404; to enable pathinfo try_files $uri =404; #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; #include pathinfo.conf;}
這個樣子,就能正常訪問到PHP。這個是為什嗎?
不同在於:
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
試檢查你的 fastcgi 具體在監聽哪一個 socket。