【问题标题】:Laravel 502 Bad Gateway ErrorLaravel 502 错误网关错误
【发布时间】:2016-10-29 13:00:07
【问题描述】:

我使用 Laravel 5.3 和最新的 Homestead 设置。当我向我的 API 发出 POST 请求时,我根据日志文件收到此错误:

2016/10/29 12:44:34 [错误] 776#0: *28 recv() 失败(104:连接 由对等方重置)同时从上游读取响应标头,客户端: 192.168.10.1,服务器:loc.medifaktor,请求:“POST /api/v1/mfusers HTTP/1.1”,上游:“fastcgi://unix:/var/run/php5-fpm.sock$

我使用 POSTMAN 将 POST 请求发送到 URL: http://loc.medifaktor/api/v1/mfusers

这是一个宅基地安装并在我的计算机上本地运行。

这个错误中提到的客户端地址是 192.168.10.1 这实际上是不正确的,因为我使用的是 192.168.10.10。这可能是错误吗?我该如何改变?

[![在此处输入图片描述][1]][1]

我正在使用全新安装的 Laravel,并尝试了其他请求,例如 GET,它们运行良好。只是 POST 请求会引发此错误。

php-fpm.log 显示:

[29-Oct-2016 13:47:15] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful

这是 nginx 配置的输出:

server {
    listen 80;
    listen 443 ssl;
    server_name loc.medifaktor;
    root "/home/vagrant/Development/Source/MFServer/public";

    index index.html index.htm index.php;

    charset utf-8;

    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/loc.medifaktor-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
        deny all;
    }

    ssl_certificate     /etc/nginx/ssl/loc.medifaktor.crt;
    ssl_certificate_key /etc/nginx/ssl/loc.medifaktor.key;
}

【问题讨论】:

  • 你能显示你的 PHP-FPM 错误日志吗?
  • 我只在var/log文件夹中找到了php-fpm.log文件(已编辑问题)
  • 错误日志不够清晰...但也许你可以尝试在你的php-fpm配置文件中设置catch_workers_output = yes。它将工人标准输出和标准错误重定向到主错误日志。
  • 如果有帮助,我也添加了 nginx 配置?
  • 我猜你的 nginx 配置没有问题。几个月前我和你有同样的问题。这些就是我所做的。将pm.max_requests 更新为500 并重新启动fpm 服务sudo service php5-fpm restart。希望它也对你有用。

标签: php laravel


【解决方案1】:

在您网站的 nginx sites_enabled conf 文件中将您的 fastcgi_pass 更改为 127.0.0.1:9000。

【讨论】:

  • 这太疯狂了,但它是唯一对我有帮助的事情。很高兴知道为什么需要进行此更改。
【解决方案2】:

如果您最近运行了 sudo apt-get update 并安装了新版本的 PHP,并使用 nginx,请确保您已更新 /etc/nginx/sites-enabled 中的 fastcgi_pass 设置,例如:

fastcgi_pass unix:/run/php/php7.3-fpm.sock;

您还应该确保安装最新版本的 pdo_pgsql 扩展。

【讨论】:

    【解决方案3】:

    请记住,您的 PHP 版本必须与您指定的 fastcgi_pass fpm 相匹配。短袜。例如,您有 php 版本 7.4。那么你应该使用下面的代码。

    fastcgi_pass unit:/run/php7.4-fpm.sock
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-07
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2020-08-27
      • 2017-03-28
      相关资源
      最近更新 更多