Reverse Proxy issue

sysautomation
sysautomation used Ask the Experts™
on
Hello

For some reasons I need to access https://api.postcodeapi.nu/ with http instead of https. I have created a reverse proxy in my Apache as following:

<VirtualHost 127.0.0.1:80>
ServerName api.postcodeapi.nu.local
SSLProxyEngine on
ProxyPass / https://api.postcodeapi.nu/
ProxyPassReverse / https://api.postcodeapi.nu/
</VirtualHost>

Open in new window


Added following line in /etc/hosts

127.0.0.1      api.postcodeapi.nu.local

Open in new window


and accessing with curl but get Bad gateway:

# curl http://api.postcodeapi.nu.local
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Bad Gateway</title>
</head><body>
<h1>Bad Gateway</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
</p>
</body></html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018

Commented:
Most probably because the Host header is not changed with the revers proxy you have.
The remote server expects hostname: api.postcodeapi.nu  
(ie without the .local).

Author

Commented:
Hi nocci

How can I do it? Any tips?
nociSoftware Engineer
Distinguished Expert 2018

Commented:
For apache i think you need to add:

RequestHeader set Host "api.postcodeapi.nu"
ProxyPreserveHost On

I don't use Apache though, so cant verify.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Author

Commented:
Already tried that without luck.

Author

Commented:
I tried my original proxy pass configuration in CentOS 7 running Apache/2.4.6 and it works without a problem.

However I have to run it with CentOS 6 as it is not possible to upgrade the O/S at the moment.
Software Engineer
Distinguished Expert 2018
Commented:
Isn't there a Apache/2.4.x available in an alternate repository for Centos 6?  

This might help:

$ yum --enablerepo=extras install  centos-release-scl
$ yum install   httpd24

Author

Commented:
Apache 2.4 does the job. Not sure why 2.2 cannnot.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial