3

我正在努力让 nginx 启动并使用 php5-fpm 运行。我觉得这是我忽略的一个小细节,所以我休息了几天,然后又回来了。今晚又搞砸了几个小时,但无济于事。

无论如何,这是问题所在:我已经启动并运行了 nginx。它似乎可以正确地提供网页。例如,http://www.shidenadvanced.com的基础网站服务就很好。但是,位于http://www.shidenadvanced.com/test.php的 php 测试返回为空白。以前它作为 502 坏网关返回。

通过我的研究,我了解到这意味着它无法通过 php-fpm 正确路由它。不是100%。

这是我的 /sites-available/config:

server {
    server_name www.shidenadvanced.com shidenadvanced.com;
    access_log /srv/sites/shidenadvanced/logs/access.log;
    error_log /srv/sites/shidenadvanced/logs/error.log;

    root /srv/sites/shidenadvanced/www;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.html;
    }

    #location ~ \.php$ {
    #    try_files $uri =404;
    #    include /etc/nginx/fastcgi_params;
    #    fastcgi_pass unix:/var/run/php-fpm5.sock;
    #    fastcgi_index index.php;
    #    fastcgi_param SCRIPT_FILENAME /srv/sites/shidenadvanced/www$fastcgi_script_name;
    #}

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

除此之外,我只保留了大部分设置。不完全确定发生了什么。任何人都可以解释一下吗?

4

2 回答 2

2

尝试这个。我对您处理 fastcgi 的方式进行了一些更改

server {
server_name www.shidenadvanced.com shidenadvanced.com;
access_log /srv/sites/shidenadvanced/logs/access.log;
error_log /srv/sites/shidenadvanced/logs/error.log;

root /srv/sites/shidenadvanced/www;
index index.php index.html index.htm;

location / {
    try_files $uri $uri/ /index.html;
}

# use fastcgi for all php files
location ~ \.php$
{
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.ht {
    deny all;
}
}
于 2013-01-26T08:11:39.910 回答
2

我个人更喜欢socket解决方案:

fastcgi_pass unix:/path/tp/myfirst.socket;

代替

fastcgi_pass 127.0.0.1:9000;

但您也需要主机的 fpm 配置:

[hak-rentrisch_de]
listen = /path/tp/myfirst.socket
listen.owner = hostuser
listen.group = hostgroup
listen.mode = 0666

listen.backlog = -1
listen.allowed_clients = 127.0.0.1

user = hostuser
group = hostgroup

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500

php_admin_value[include_path] = .:/var/www/libs 
[...]

亲切的问候

于 2013-01-26T08:23:40.983 回答