Erro 502 Bad Gateway help

Discussion in 'Nginx' started by sohail, Mar 16, 2015.

  1. sohail

    sohail Administrator Staff Member

    Hi I'm setting up a nginx as a reverse proxy but to try to see a site with drupal locally that have shown me 502 Bad Gateway error.
    this gets me in the logs.

    016/07/02 00:51:57 [error] 18120#0: *61 upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream, client:, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://", host: " localhost"

    I can not get him out of there I find that causes this error. the server operating system is a gentoo. I show my vhost
    server {
    listen 80;
    server_name localhost;
    access_log /var/log/nginx/localhost_access_log main;
    error_log /var/log/nginx/localhost_error_log info;
    root /var/www/site/prueva/www/;
    location / {
    index index.html index.htm index.php;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
    location ~ \.php$ {
    # Test for non-existent scripts or throw a 404 error
    # Without this line, nginx will blindly send any request ending in .php to php-fpm
    try_files $uri =404;
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass; ## Make sure the socket corresponds with PHP-FPM conf file

    Attached Files:

    Last edited: Jul 7, 2016
  2. sohail

    sohail Administrator Staff Member

    Where did you PHP install?
    You can edit /path/to/php_dir/etc/php-fpm.conf,or sometimes there will be a
    dir called 'www.conf.d',if it is,please change in the directory,and edit
    www.conf which is in the www.conf.d.
    You will find a option called 'listen' in the configuration file below,make
    sure the option's content is '',if not,you can edit it as
    ''.You can also edit the nginx configuration file,change the
    option 'fastcgi_pass'.
    But I recommend use socket to connect php-fastcgi,it is faster.To do
    this,just change the php-fpm.conf or www.conf likes follow:
    listen = /dev/shm/php-cgi.sock
    listen.owner = www = www
    listen.mode = 0660

    '...'just stands for something omitted.
    And then change the 'fastcgi_pass' option to
    'unix:/dev/shm/php-cgi.sock',restart nginx and PHP,all done!

    P.S:My mother tongue isn't English,if there is something you couldn't
    understand,please let my konw,thanks!



    12345 at
    Last edited: Jul 16, 2016
  3. sohail

    sohail Administrator Staff Member


    Attached Files: