【问题标题】:Cannot get PHP to serve on Nginx — Error 404无法让 PHP 在 Nginx 上服务 - 错误 404
【发布时间】:2014-02-09 03:56:15
【问题描述】:

我对 nginx 相当陌生,并认为使用它来提供 php 会非常简单,因为这种设置非常常见,但它似乎比我预期的要复杂得多。

这是我的配置..

server {
        listen 80;
        server_name domain.com www.domain.com;

        location / {
                root   /srv/www/domain.com/public_html;
                index index.php;
        }

# serve static files directly
#location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$
#    access_log        off;
#    expires           30d;

        location ~ [^/]\.php(/|$) {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                }

                fastcgi_pass /var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

如果我用“index.html”文件替换“index.php”,nginx 会完美地提供 html。

我看过一些指南建议修改任何内容,从 iptables 到 php-fpm 到 php.ini,再到 fast-cgi 到 sites-available..?

我不确定这些教程中的许多到底想做什么......现在我只想让我的 index.php 提供 phpinfo()。排除 404 错误的下一步是什么?

是否有一个明确的指南来介绍可用于使用 nginx 提供 php 的各种选项?

Debian Wheezy 7.3 on xen

【问题讨论】:

    标签: php nginx


    【解决方案1】:

    试试这个配置:

    server {
        listen   80;
        server_name domain.com www.domain.com;
        root /srv/www/domain.com/public_html;
        index index.php;
    
        location ~ ^(.+\.php)(/.*)?$ {
            fastcgi_pass  localhost:9000;
            include fastcgi_params;
        }
    }
    

    (假设您的 index.php 文件位于 /srv/www/domain.com/public_html)

    【讨论】:

    • 要修复 502,我必须将 /etc/php5/fpm/pool.d/www.conf 中的一行从 .sock 更改为 listen = 127.0.0.1:9000
    • 如果系统已经配置为处理 sock 文件,为什么要更改为端口?
    猜你喜欢
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多