>백엔드 개발 >PHP 튜토리얼 >Nginx识别PHP文件

Nginx识别PHP文件

WBOY
WBOY원래의
2016-06-06 20:29:101418검색

Nginx的配置文件server块里面有对PHP文件的识别和转发。

<code>
 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;
}
</code>

这段正则可以识别PHP结尾的文件。
但是为什么我访问`http://123.123.123.123/abc.abc.acb/index.php'
就出现了502错误?
如果我把上面的正则重复一遍就好了。

<code>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;
}
</code>

这个样子,就能正常访问到PHP。这个是为什么?

回复内容:

Nginx的配置文件server块里面有对PHP文件的识别和转发。

<code>
 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;
}
</code>

这段正则可以识别PHP结尾的文件。
但是为什么我访问`http://123.123.123.123/abc.abc.acb/index.php'
就出现了502错误?
如果我把上面的正则重复一遍就好了。

<code>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;
}
</code>

这个样子,就能正常访问到PHP。这个是为什么?

不同在于:
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;

试检查你的 fastcgi 具体在监听哪一个 socket。

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.