How I fixed Nginx 502 Bad Gateway error

Today to my grate surprise I got “502 Bad Gateway” error while trying to open some specific URL on my web site:

Nginx 502 Bad Gateway

I took a look at the Nginx log file located in /var/log/nginx/ directory on my machine and seen the following:


2012/09/17 16:48:47 [error] 15421#0: *16 upstream sent too big header while reading response header from upstream, client: 192.168.1.5, server: milomag.ru, request: “GET /store/rastitelnie-extrakty HTTP/1.1″, upstream: “fastcgi://unix:/var/run/www-beauty.sock:”, host: “milomag.ru”, referrer: “…”

After doing a simple Google search I solved the problem by adding two lines to Nginx configuration file /etc/nginx/nginx.conf :

http {
    ...
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    ...
}

33 Responses to How I fixed Nginx 502 Bad Gateway error

  1. M1 on January 9, 2013 at 1:46 AM:

    thanks for this. had the same prob. fixed my prob also.

  2. bill on January 22, 2013 at 9:23 AM:

    solved the problem

  3. tin tuc 9x on February 5, 2013 at 12:04 AM:

    i fix error

  4. andrej on March 3, 2013 at 12:25 AM:

    This also solved the problem Nginx 502 Bad Gateway error on my site

  5. 0108SR on March 7, 2013 at 5:16 PM:

    Ohh.. how nice. But it is too technical for me. Can u please let me have a step by step guidance? I have Internet Explorer 7 and use Windows Vista Home Edition.

    Thnx in advance

    • dmitriano in reply to 0108SR on March 7, 2013 at 5:39 PM:

      Hello! You need Ubuntu Linux, not Windows :) Seriously, the “502 Bad Gateway” error happens on the web server, so it doesn’t matter what OS you’re running and what browser you’re using.

  6. boem on March 11, 2013 at 5:16 PM:

    This magically solved my problem. I thought it was about joomla internal rewrite engine conflicting with nginx configuration and spent hours trying to figure out the solution from that angle.

  7. gijs on March 16, 2013 at 4:34 PM:

    lol, so if i see this when visiting a website (wich isn’t mine) this website just totally crashed right .___.

    • dmitriano in reply to gijs on March 16, 2013 at 6:29 PM:

      I’m not sure about “totally crashed”, but I can say with certainty that it does not work at the moment :)

  8. Luckyfire on March 23, 2013 at 4:10 PM:

    Works great! realy helps. Thank You!

  9. Davor on March 26, 2013 at 5:40 PM:

    doesn´t solved my problem… but thx for help

  10. Paul on April 3, 2013 at 2:38 PM:

    Did not solve my 502 error either, so there must be a couple of solutions. This is obviously one of them though. Thanks for posting a solution – even if it didnt solve mine !

  11. Francisco on April 11, 2013 at 10:44 AM:

    Good morning,

    I am also having this message when I try to log to my Warez-bb account:

    “502 BAD gateway – NGINX”

    I want to try your solution but I am unable to finde the “path” /etc/nginx/nginx.conf

    How do I access NGINX configruation page? I’m running W7 64bit.

    Thanks!

    Regards

    • dmitriano in reply to Francisco on April 11, 2013 at 7:31 PM:

      Hello! I suppose something temporarily wrong with the web site you are trying to open.

    • Noxxim in reply to Francisco on April 19, 2013 at 5:22 AM:

      You can’t fix this on your (Browser) side. It’s a Server issue.

  12. Paul Thomson on July 22, 2013 at 6:08 AM:

    Seems to have done the trick,

    Keep up the good work, stay safe!
    Paul :-)

  13. John on August 18, 2013 at 11:36 PM:

    It got rid of the problem… Thanks!

  14. Sepp on August 27, 2013 at 5:54 PM:

    This also solved the problem Nginx 502 Bad Gateway error on my Magento site.
    Thank You!

  15. Claude on September 1, 2013 at 6:57 AM:

    Is there a reason why this has started happening recently on various sites where it never happened previously?

    Is there anything I can do about it as a users of the sites?

    • dmitriano in reply to Claude on September 1, 2013 at 7:15 AM:

      Hello, Claude! One of the possible reasons is a software update or some changes in Nginx configuration. If you have the access to Nginx configuration files there are a lot of things you can do.

  16. WIlson on November 3, 2013 at 4:26 PM:

    Fixed my problem also! Tanks and success!

  17. Nyein Nyein on November 15, 2013 at 5:20 AM:

    I faced “502 Bad Gateway : ngix” error at my site. To solve this problem, I used this “/etc/nginx/nginx.conf” at command. But When I entered it, it appear this error “blush : access denied for /etc/nginx/nginx.conf”.
    If so , I can’t continue to run your following code
    http {

    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;

    }
    How can I fixed this error. Please can you give your advice.

    • superadmin in reply to Nyein Nyein on November 15, 2013 at 8:29 AM:

      Probably you need the root access to “/etc/nginx/nginx.conf”, try sudo -s or something like this.

  18. Tezel Celebi on December 13, 2013 at 7:50 AM:

    hi dmitriano,

    thanks for the simple and great solution. it worked !!

  19. zodiac signs on December 22, 2013 at 9:49 AM:

    Thank you
    By reading your articles I’ve solved my own

  20. Rajavamsidhar chowdary on January 2, 2014 at 12:46 PM:

    Fixed my problem!! Thanks a lot

  21. Post job free on January 3, 2014 at 9:11 AM:

    Fixed the problem, but next to how much should i increase the value?

  22. Grateful Developer on February 24, 2014 at 1:13 AM:

    Fixed my problem too – thanks!

  23. Dealsoff on March 8, 2014 at 9:05 PM:

    This fixed my 502 gateway problem. Thanks i found this website.

  24. Michel on April 9, 2014 at 12:03 PM:

    I’m having this problem on my iPhone 4S. Any solution?

  25. hack game android on June 25, 2014 at 4:27 PM:

    Thanks, i fixed that

  26. Ali on July 12, 2014 at 6:20 PM:

    I had the same problem and There was no directory or config file as stated above, What worked for me was:
    going to command com, cmd.exe and doing DNS flush:

    How to clear dns cache on Windows XP, 2000, Vista or Windows7 OS?
    Open the Windows Start menu.
    Go to Run.
    If you do not see the Run command in Vista, search for “run” in the Search bar.
    In the Run text box, type: ipconfig /flushdns
    Press Enter or Return, and dns cache of Windows OS will be flushed.

    How to clear dns cache on MacOS?
    Go to Applications.
    Go to Utilities.
    Open the Terminal application.
    Type: dscacheutil -flushcache
    Press Enter or Return, and your MacOS DNS cache will be cleared.

  27. Tunive on August 8, 2014 at 4:01 AM:

    Thanks, i fixed that!!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>