Home  >  Q&A  >  body text

nginx - The server always appears 502 Bad Gateway?

nginx+tomcat cluster construction

But 502 bad Gateway always starts to appear at 7 or 8 o'clock every day.

Can someone help me analyze the reasons for various situations?

error.log record

2014/10/07 07:59:47 [error] 7783#0:
*90920 connect() failed (111: Connection refused) while connecting to upstream, client: 124.133.28.7, server: xx.com, request: "GET / HTTP/1.1", upstream: "http://127.0.1.1: 8888/", host: "xx.com"

曾经蜡笔没有小新曾经蜡笔没有小新2712 days ago583

reply all(4)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:28:27

    Access directly on the server through http://127.0.1.1:8888/ to see if the site is available, and then determine whether there is an nginx configuration problem.

    reply
    0
  • 迷茫

    迷茫2017-05-16 17:28:27

    Have you added keepalive configuration to your upstream?

    upstream backend {
        server http://127.0.0.1:8888;
        keepalive 32;
    }
    

    Establish a long connection between nginx and backend to avoid repeatedly creating tcp connections when a large number of requests are made, otherwise 502 will easily occur

    I think your situation is related to the specific time period. It is probably caused by the large number of concurrent requests during this time period

    In addition, check the memory and CPU usage of your application server during this period. It is also possible that a code bug causes the application server to be unable to respond to more connections

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 17:28:27

    Maybe there is a problem with the tomcat server or there is a bug in the code

    Look at the tomcat log, there may be relevant information

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:28:27

    When the tomcat server is inaccessible, ngnix will report 502

    reply
    0
  • Cancelreply