'How to setup apache 2 reverse proxy to forward different domain and pretend as that domain name?

I am using Debian and apache2, I don't know if it is possible to use apache to reverse proxy from one domain to another domain, but the backend server behind the latter server still consider the requesting URL is of the latter?

For example if you visit https://www.example.com/index.html, the request will forward to https://www.example.org/index.html, but in the backend server of www.example.org still think the requesting URL is https://www.example.org/index.html, not https://www.example.com/index.html

I think I need to change the X-Forwarded-Server header in the apache proxying, but I don't know how. Any help would be highly appreciated.



Solution 1:[1]

The behavior you describe is the default behavior:

If example.com has the following configuration:

ProxyPass / http://example.org/

And I go to http://example.com/, then example.org will see the following request (check the Host header):

GET / HTTP/1.1
Host: example.org
[...]
X-Forwarded-For: <client IP address>
X-Forwarded-Host: example.com

With ProxyPreserveHost On, you change this behavior and get

GET / HTTP/1.1
Host: example.com
[...]
X-Forwarded-For: <client IP address>
X-Forwarded-Host: example.com

Unless example.org uses the X-Forwarded-Host header to decides what content to serve, you're good.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Duponchel