65

We are building a mass mailing sending application in Java. Mail is being send by third party SMTP. After sending 400-500 mails tomcat6 service get stopped. Below is the error.

Proxy Error The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /lin/Campaignn.jsp. Reason: Error reading from remote server

Additionally, a 502 Bad Gateway error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at msizzler.com Port 80

But when we are sending from localhost I did not received any error. It send all the mails. Please help me to sort it out this problem.

Yurets
  • 3,999
  • 17
  • 54
  • 74
Ranjeet Ranjan
  • 921
  • 2
  • 10
  • 21
  • odoo: The proxy server received an invalid response from an upstream server Same issue we face, but with proxy timeout fixed issue – Tejas Tank Aug 21 '19 at 15:43

5 Answers5

54

The HTTP 502 "Bad Gateway" response is generated when Apache web server does not receive a valid HTTP response from the upstream server, which in this case is your Tomcat web application.

Some reasons why this might happen:

  • Tomcat may have crashed
  • The web application did not respond in time and the request from Apache timed out
  • The Tomcat threads are timing out
  • A network device is blocking the request, perhaps as some sort of connection timeout or DoS attack prevention system

If the problem is related to timeout settings, you may be able to resolve it by investigating the following:

  • ProxyTimeout directive of Apache's mod_proxy
  • Connector config of Apache Tomcat
  • Your network device's manual
rmeakins
  • 1,309
  • 8
  • 13
49

Add this into your httpd.conf file

Timeout 2400
ProxyTimeout 2400
ProxyBadHeader Ignore 
Ian Hunter
  • 9,466
  • 12
  • 61
  • 77
Albert Maclang
  • 507
  • 4
  • 2
  • These directives work great under Centos 6.6 with Apache 2.2.15. Thanks! – James Wong Feb 04 '15 at 07:03
  • 1
    This worked well for a Tomcat8 app running with apache 2.4 where an operation was clearly timing out from time to time. – gringogordo Jun 19 '15 at 10:23
  • It worked for Tomcat 7 under apache on centos. Thanks !! – jkb016 Jan 27 '16 at 19:45
  • 3
    According to Apache docs "Timeout" syntax is actually "TimeOut" for anyone who this may help. – Karl Jan 12 '17 at 21:42
  • This is not working for me. Do it need to restart the tomcat after changing this timeout configuration? – Rose18 Jan 04 '18 at 03:50
  • How can I do it in AWS Beanstalk application ? – AL̲̳I Oct 01 '18 at 15:22
  • In 2022, this solution does not work with me. The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /about. ?? Can anyone solve this issue? Can anyone solve this issue? – Abdulrahman Fawzy Jul 04 '22 at 16:29
5

The java application takes too long to respond(maybe due start-up/jvm being cold) thus you get the proxy error.

Proxy Error

The proxy server received an invalid response from an upstream server.
 The proxy server could not handle the request GET /lin/Campaignn.jsp.

As Albert Maclang said amending the http timeout configuration may fix the issue. I suspect the java application throws a 500+ error thus the apache gateway error too. You should look in the logs.

Anthony Hunt
  • 1,470
  • 5
  • 20
  • 32
5

I had this issue once. It turned out to be database query issue. After re-create tables and index it has been fixed.

Although it says proxy error, when you look at server log, it shows execute query timeout. This is what I had before and how I solved it.

DimaSan
  • 12,264
  • 11
  • 65
  • 75
CincyBella
  • 109
  • 1
  • 4
  • 3
    I had a similar problem just now. Except I was receiving the proxy error because I had accidentally overwritten the connection string to my database with that of another site... and now I feel dumb. This career is both awesome and painful at the same time >. – mbuchok Nov 26 '20 at 23:38
0

I had this problem too. I was using apache as a reverse proxy for tomcat, my problem was associated with the return time of the response for "apache" proxy

I solved it like this: open the "etc/apache/apache2.conf" and the ssl mod conf file "etc/apache/sites-available/000-default-le-ssl.conf" and add the following lines:

Timeout 28800
KeepAlive On

maybe this will help you