When I try to view my website homepage I get the following error dislayed: 502 Bad Gateway Nginx

The error log found at /var/log/nginx shows the message: *2014/04/21 10:30:39 [error] 3807#0: 228 upstream sent invalid header while reading response header from upstream, client:, server: agronegocios.eu, request: "GET / HTTP/1.1", upstream: (MyIPaddress):7080/", host: "agronegocios.eu"

My environment: CentOS 6.5; PHP 5.3.3; nginx/1.5.0; MySQL 5.1.73; Joomla 3.2.3 Anyone know how can I get rid of this problem? I´ve seen some related questions and answers but none is to the same problem...(and also I'm not an expert on linux servers...). Thanks.

My nginx.conf file:

#user  nginx;
worker_processes  1;

#error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

#pid        /var/run/nginx.pid;

events {
  worker_connections  1024;

http {
  include       mime.types;
  default_type  application/octet-stream;

  #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  #                  '$status $body_bytes_sent "$http_referer" '
  #                  '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log  /var/log/nginx/access.log  main;

  sendfile        on;
  #tcp_nopush     on;

  #keepalive_timeout  0;
  keepalive_timeout  65;
  #tcp_nodelay        on;

  #gzip  on;
  #gzip_disable "MSIE [1-6]\.(?!.*SV1)";

fastcgi_buffers 8 16k;
  fastcgi_buffer_size 32k;
  server_tokens off;

  include /etc/nginx/conf.d/*.conf;
  • Could you show us your nginx config? Apr 21, 2014 at 11:05
  • Look at the php/fastcgi log, it's typically an error in the upstream service Apr 22, 2014 at 18:51

2 Answers 2


I detected where (yet not what) was causing the error: a template module in the CMS extensions that is not working properly. Disabling the module made the error go away. Anyway, thanks for your opinions and efforts!


I was an administrator for a McAfee Web Gateway product in another job that I had. While not Nginx, it's a RHEL proxy server operating on standard HTTP response codes.

Whenever I received a Bad Gateway error, it's always been an upstream device causing the issue. The error, as I understand, means that the proxy received a response from the upstream device that it didn't like. My environment had many "homegrown" apps, and it was typically found that the app was not properly communicating per the RFCs. Other times we found it was issues with unparsable headers that we needed to create a policy to exempt those sites from deep header inspection. I'm going to try to remember what headers it was tripping over, and I'll repost back here when I find out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.