Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retaining protocol and port number from reverse proxy request

Case:

User requests https://api.abc.com

This is reverse proxied (Apache 2.2) to an internal server server at http://internal.abc.com:123

As per Retain original request URL on mod_proxy redirect , by adding:

ProxyPreserveHost On

to httpd.conf, internal.abc.com currently recognizes the original request url as:

http://api.abc.com:123

Is there any way for me to recover the original URL of https://api.abc.com ? That is, to also retain the original protocol (http) and port (80, or empty is also fine)

like image 342
ChaimKut Avatar asked Feb 06 '14 09:02

ChaimKut


People also ask

What is ProxyPass and ProxyPassReverse in Apache?

The "ProxyPass" and "ProxyPassReverse" parameters are used to tell Apache how to proxy requests. They require the "mod_proxy.so" and "mod_proxy_http.so" Apache modules, which are loaded by default in RHEL5 and RHEL6, but check the following lines are uncommented in the "/etc/httpd/conf/httpd. conf" file to make sure.

What is ProxyPassReverse?

The ProxyPassReverse is used to change the headers sent to Apache from a proxied app server, before Apache sends it to the browser.

What is mod_proxy in Apache?

mod_proxy is an optional module for the Apache HTTP Server. This module implements a proxy, gateway or cache for Apache. It implements proxying capability for AJP13 (Apache JServ Protocol version 1.3), FTP, CONNECT (for SSL), HTTP/0.9, HTTP/1.0, and (since Apache 1.3. 23) HTTP/1.1.

What is Proxyrequests?

When you send a web request, your request goes to the proxy server first. The proxy server then makes your web request on your behalf, collects the response from the web server, and forwards you the web page data so you can see the page in your browser.


1 Answers

You need this parameter RequestHeader set X-Forwarded-Proto "https", without this, the returned location will be http://api.abc.com.

ProxyRequests Off
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"

ProxyPass / http://internal.abc.com:123
ProxyPassReverse / http://internal.abc.com:123

With this configuration, both queries (from lan and wan) will work fine:

https://api.abc.com
http://internal.abc.com:123
like image 65
Stéphane Millien Avatar answered Oct 16 '22 17:10

Stéphane Millien