Oli013 Oli013 - 5 days ago 5
Apache Configuration Question

Redirect a virtualhost http & https to another virtualhost server

I have 2 apache 2.4 serverA and serverB with several virtualhost. All incoming requests arrive on serverA.

How do I forward http and https request for a specific virtualhost name from serverA to serverB?

My wamp ServerA setup is:
into my hosts file
127.0.0.7 example.com

The virtualhost:

<VirtualHost *:*>
ServerName example.com
ProxyPreserveHost On
ProxyPass "/" "http://192.168.1.105/"
ProxyPassReverse "/" "http://192.168.1.105/"
</VirtualHost>


My serverB ip is 192.168.1.105 and I setup a virtual host on it with the same name example.com

when I use
http://example.com
I stay on the wamp home page like
http://localhost

and when I use
https://example.com
I have error 403 (Forbidden) on serverA

Answer

After a long night, I find a solution:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass         "/" "http://192.168.1.105/"
    ProxyPassReverse  "/" "http://192.168.1.105/"
    ServerName        example.com
</VirtualHost>
<VirtualHost *:443>
    SSLProxyEngine on
    SSLCertificateFile    "${APACHE_DIR}/conf/ssl_example.com/server.crt"
    SSLCertificateKeyFile "${APACHE_DIR}/conf/ssl_example.com/server.key"
    ErrorLog  "logs/example.com-ssl_error.log"
    CustomLog "logs/example.com-ssl_access.log" common
    ProxyPreserveHost On
    ProxyPass         "/" "https://192.168.1.105/"
    ProxyPassReverse  "/" "https://192.168.1.105/"
    ServerName        example.com
</VirtualHost>
Comments