# Erro 502 Bad Gateway help

**URL:** <https://www.ruby-forum.com/t/erro-502-bad-gateway-help/244886>\
**Category:** NGINX\
**Created:** [July 2, 2016, 8:30am UTC](https://www.ruby-forum.com/t/erro-502-bad-gateway-help/244886 "2016-07-02T08:30:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [July 2, 2016, 8:30am UTC](https://www.ruby-forum.com/t/erro-502-bad-gateway-help/244886/1 "2016-07-02T08:30:16Z")

</div>

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: 127.0.0.1, server: localhost, request: “GET /  
HTTP/1.1”, upstream: “fastcgi://127.0.0.1:8080”, 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 127.0.0.1:8080; ## Make sure the  
socket corresponds with PHP-FPM conf file  
}  
}

---

<div class="post-metadata">

**Author:** ![yair\_avendaSSo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/85e7bf/32.png) [@yair\_avendaSSo](https://www.ruby-forum.com/u/yair_avendaSSo)\
**Post date:** [July 2, 2016, 9:05am UTC](https://www.ruby-forum.com/t/erro-502-bad-gateway-help/244886/2 "2016-07-02T09:05:19Z")

</div>

Hello,  
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 ‘127.0.0.1:8080’,if not,you can edit it as  
‘127.0.0.1:8080’.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:  
[www]  
…  
user=www  
group=www  
…  
listen = /dev/shm/php-cgi.sock  
listen.owner = www  
listen.group = 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!  
2016-07-02 14:21 GMT+08:00 yair avendaño [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![yair\_avendaSSo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/85e7bf/32.png) [@yair\_avendaSSo](https://www.ruby-forum.com/u/yair_avendaSSo)\
**Post date:** [July 2, 2016, 9:25am UTC](https://www.ruby-forum.com/t/erro-502-bad-gateway-help/244886/3 "2016-07-02T09:25:46Z")

</div>

On Sat, Jul 02, 2016 at 06:21:38AM +0000, yair avendao wrote:

Hi there,

> 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.

“drupal” is possibly served by a http server, not a fastcgi server.

> 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:  
> 127.0.0.1, server: localhost, request: “GET / HTTP/1.1”, upstream:  
> “fastcgi://127.0.0.1:8080”, host: " localhost"

If you make a bad http request to a http server, it will likely return  
something that starts with “HTTP”. The decimal value of ascii “H” is  
“72”; a fastcgi client may expect the first octet to refer to the  
fastcgi  
protocol version.

So your error message hints that your upstream is not a fastcgi server  
but is a http server.

Which in turn suggests that the fix is:

> ```
> 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;
> 
> ```

- delete those two

> ```
> fastcgi_pass 127.0.0.1:8080; ## Make sure the socket 
> 
> ```

corresponds with PHP-FPM conf file

- replace that with

---

<div class="post-metadata">

**Author:** ![yair\_avendaSSo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/85e7bf/32.png) [@yair\_avendaSSo](https://www.ruby-forum.com/u/yair_avendaSSo)\
**Post date:** [July 3, 2016, 3:03am UTC](https://www.ruby-forum.com/t/erro-502-bad-gateway-help/244886/4 "2016-07-03T03:03:04Z")

</div>

Hi. You must use fastcgi\_pass if you use fastcgi server as backend e.g.  
php-fpm. If you use apache as backend you must use proxy\_pass.  
2 июля 2016 г. 10:25 пользователь “Francis D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
написал:

On Sat, Jul 02, 2016 at 06:21:38AM +0000, yair avendaño wrote:

Hi there,

> 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.

“drupal” is possibly served by a http server, not a fastcgi server.

> 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:  
> 127.0.0.1, server: localhost, request: “GET / HTTP/1.1”, upstream:  
> “fastcgi://127.0.0.1:8080”, host: " localhost"

If you make a bad http request to a http server, it will likely return  
something that starts with “HTTP”. The decimal value of ascii “H” is  
“72”; a fastcgi client may expect the first octet to refer to the  
fastcgi  
protocol version.

So your error message hints that your upstream is not a fastcgi server  
but is a http server.

Which in turn suggests that the fix is:

> ```
> 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;
> 
> ```

- delete those two

> ```
> fastcgi_pass 127.0.0.1:8080; ## Make sure the
> 
> ```

socket corresponds with PHP-FPM conf file

- replace that with

–  
Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
