Nodejs proxied from apache: The proxy server received an invalid response from an upstream server

apache-2.4node.jsproxypass

I have nodejs server and some static content to serve. I am using apache 2.4 for this purpose as I need to configure multiple hosts on same machine.

I have following configuarion for my virtual host in my apache 2.4

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin admin@mydomain.co.in
    ServerName mydomain.co.in
    ServerAlias mydomain.co.in
    ProxyPass /api http://127.0.0.1:3001/api
    ProxyPassReverse /api http://127.0.0.1:3001/api
    DocumentRoot /root/VEFA-test-admin/vefa-admin/platforms/browser/www
    <Directory /root/VEFA-test-admin/vefa-admin/platforms/browser/www>
                Options -Indexes +FollowSymLinks +MultiViews
                AllowOverride All
                Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/encrypt/live/mydomain.co.in/fullchain.pem
SSLCertificateKeyFile /etc/encrypt/live/mydomain.co.in/privkey.pem
</VirtualHost>
</IfModule>

And my nodejs server is running on portt 3001 on same machine.
The problem is user who will be access my site using mydomain.co.in gets to see the page. But in one scenario I am redirecting user to payment gateway and payment gateway is redirecting user bak on my site after payment. The problem occurs when payment gateway redirects user to my site.

The apache error log says this:

[Thu Sep 07 12:08:06.291298 2017] [proxy_http:error] [pid 12226:tid 139763780601600] (20014)Internal error (specific information not available): [client 219.91.211.175:11159] AH01102: error reading status line from remote server 127.0.0.1:3001, referer: https://test.payumoney.com/payment/postBackParam.do
[Thu Sep 07 12:08:06.291358 2017] [proxy:error] [pid 12226:tid 139763780601600] [client 219.91.211.175:11159] AH00898: Error reading from remote server returned by /api/u/payments/success, referer: https://test.payumoney.com/payment/postBackParam.do

What wrong am I doing here??

I have tried all solutions I am mentioning below

I have tried to use Keepalive on,ProxyBadHeader Ignore but nothing helped me out. Can some one help me?

Best Answer

The app being proxied to is not speaking valid HTTP. Whatever is coming back from the nodejs process in response to the HTTP request that Apache is making is not HTTP. I'm not sure how else to explain it...