时间:2021-07-01 10:21:17 帮助过:4人阅读
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。