Search code examples
apachevirtualhostmod-proxy

Apache - Using Virtual_host and mod_proxy together gives Access Forbidden Error


I have Apache Web Server on my Host Machine and also on my Virtual Box Machines. Host Machine's Apache web server is serving my sites perfectly.

I have forwarded requests to my router to port 80 of my Host Machine so cannot configure it be forwarded to my Virtual Machine as well. So I thought of using Apache's Proxy capabilities.

I came across this configuration for Apache so as to forward the requests to the virtual machine when they come.

< VirtualHost *:* >
ProxyPreserveHost On
ProxyPass / http://192.168.111.2/
ProxyPassReverse / http://192.168.111.2/
ServerName hostname.example.com
< /VirtualHost > 

When I am activating this setting on my Web Server all my sites (be it on Virtual Machine or Host Machine) start giving "Access Forbidden" Error.

I am not sure what I am doing wrong.

Regards, Nitin


Solution

  • I tried the following configuration and got it working -

    < VirtualHost *:80 >
    
            ServerName mydomain.com
    
            ServerAlias *.mydomain.com
    
            ProxyPass / http://172.16.0.201
    
            ProxyPassReverse / http://172.16.0.201
    
    < /VirtualHost >
    

    Not sure if there can be a more elegant solution than this one.