0

我的大部分页面都能正常工作,但是当我尝试访问我网站的一部分时,我收到 502 Bad Gateway 错误。

我正在运行最新版本的 Laravel、nginx 和 php5-fpm。我的服务器是 AWS Ubuntu 14.04 实例。

我检查了 nginx 日志并收到以下错误

2016/07/01 19:06:29 [error] 1101#0: *8 recv() failed (104: Connection reset     by peer) while reading response header from upstream, client: [client IP here], server: [aws server IP here], request: "GET /get/request/here/build?active=talent HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "[server IP here]", referrer: "http://[server IP here]/admin?all=yes"

这是我的 fpm/pool.d/www.conf 文件(或多或少未编码的所有内容)

; Pool name
[www]

listen.owner = www-data
listen.group = www-data
;listen.mode = 0660

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
;pm.process_idle_timeout = 10s;
; pm.max_requests = 500

chdir = /
catch_workers_output = yes

这是我的 nginx/sites-available/default 文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/laravelproject/public;
    index index.php index.html index.htm;

    server_name [server-ip-here];

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

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

我怎样才能解决这个问题?

4

2 回答 2

2

验证您的 fastcgi_params 所在位置

location ~ \.php$ {
    set $php_root /var/www/laravelproject/public;
    fastcgi_pass unix:/var/run/php5-fpm.sock; // switch back when verified 
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params; // adjust to your absolute path
}
于 2016-07-01T19:48:20.323 回答
1

我在 nginx 配置中没有看到问题。

但是关于 www.conf 我看到你已经定义了监听器但没有定义监听器套接字。

所以试试这个:

[www]

user = www-data
group = www-data

listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666

pm = ondemand
pm.max_children = 4
pm.process_idle_timeout = 10s
pm.max_requests = 32
chdir = /

php_admin_flag[display_errors] = on
php_admin_flag[log_errors] = off
php_admin_value[memory_limit] = 512M
php_admin_value[post_max_size] = 128M
php_admin_value[upload_max_filesize] = 128M
于 2016-07-01T21:12:10.560 回答