Nginx识别PHP文件

WBOY
Release: 2016-06-06 20:29:10
Original
1403 people have browsed it

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>
Copy after login
Copy after login

这段正则可以识别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>
Copy after login
Copy after login

这个样子,就能正常访问到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>
Copy after login
Copy after login

这段正则可以识别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>
Copy after login
Copy after login

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

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template