PHP-FPM and Nginx: 502 Bad Gateway

后端 未结 15 1766
闹比i
闹比i 2021-01-29 18:35

Configuration

  • Ubuntu Server 11.10 64 bit
  • Amazon AWS, Ec2, hosted on the cloud
  • t1.micro instance

Before I write an

相关标签:
15条回答
  • 2021-01-29 19:09

    You should see the error log. By default, its location is in /var/log/nginx/error.log

    In my case, 502 get way because of:

    GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
    2016/05/25 11:57:28 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
    2016/05/25 11:57:29 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
    2016/05/25 11:57:29 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
    

    When we know exactly what is wrong, then fix it. For these error, just modify the buffer:

    fastcgi_buffers 16 512k; 
    fastcgi_buffer_size 512k;
    
    0 讨论(0)
  • 2021-01-29 19:13

    I've also found this error can be caused when writing json_encoded() data to MySQL. To get around it I base64_encode() the JSON. Please not that when decoded, the JSON encoding can change values. Nb. 24 can become 24.00

    0 讨论(0)
  • 2021-01-29 19:13

    Maybe this answer will help:

    nginx error connect to php5-fpm.sock failed (13: Permission denied)

    The solution was to replace www-data with nginx in /var/www/php/fpm/pool.d/www.conf

    And respectively modify the socket credentials:

    $ sudo chmod nginx:nginx /var/run/php/php7.2-fpm.sock
    
    0 讨论(0)
提交回复
热议问题