Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:, request: "GET / HTTP/1.1", upstream: (MyIPaddress):7080/", host: ""

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

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;
share|improve this question
Could you show us your nginx config? – algui91 Apr 21 '14 at 11:05
Look at the php/fastcgi log, it's typically an error in the upstream service – LinuxDevOps Apr 22 '14 at 18:51

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!

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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