首页 > 解决方案 > Laravel 502 Bad Gateway Nginx 流量高时

问题描述

我正在使用 Laravel 应用程序,下面是我的 nginx 配置代码:

server {
    listen 80;
    server_name domain.com;
    root /var/www/project/public;

    index index.html index.htm index.php index.nginx-debian.html;

    charset utf-8;
    location ~ /.well-known {
                allow all;
        }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/domain.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {
      include snippets/fastcgi-php.conf;
      fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

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

错误日志

2018/06/29 08:41:30 [error] 928#928: *14875 connect() to unix:/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: IP, server: IP, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "IP"

我的配置有问题吗?我有一台配备 32GB 内存、SSD 和处理器的重型服务器:2x E5-2670 0 @ 2.60GHz。我正在使用带有 NGINX 的 Ubuntu。

请告诉我,我已经更改了许多服务器,但无法摆脱这个问题。

标签: phplaravelubuntunginx

解决方案


检查您的 php-fpm 日志以查看 nginx 是否正在死亡。您得到的错误是 Nginx 说它正在代理请求的服务器没有响应。如果它们在两台不同的机器上,这可能是网络问题,可能是因为没有足够的工作人员来满足所有传入的请求,也可能是 VPS 上的 OOM 杀手杀死了进程。仅仅因为服务器拥有大量 RAM 并不意味着它不会受到内存耗尽的影响。我有一个 Magento 网站的客户,由于插件编码不佳,他的一天结束报告在具有类似规格的服务器上引发了内存错误。

我刚刚看到您从日志中发布了一行。检查您的 pool.conf 是否有以下内容:

process.max、pm.max_children、pm.min/max_spare_servers

这些只是您在交通繁忙的环境中可能需要调整的部分内容。


推荐阅读