繁体   English   中英

无法使PHP在Nginx上投放—错误404

[英]Cannot get PHP to serve on Nginx — Error 404

我对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.php”替换为“ index.html”文件,nginx会完美地提供html。

我看过一些指南,建议修改从iptables到php-fpm到php.ini,再到fast-cgi到网站可用的任何内容。

我不确定这些教程中有多少试图确切地做...现在,我只希望我的index.php提供phpinfo()。 解决404错误的下一步是什么?

是否有一个明确的指南,介绍了通过nginx服务php可用的各种选项?

Xen上的Debian Wheezy 7.3

试试这个配置:

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中)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM