Apache: Reverse proxy the whole domain
ProxyPass
is very nit-picky about slashes; since you're proxying a trailing slash (just the root, /
), you'll want to proxy TO a trailing slash.
So, adding some trailing slashes to your targets, as below, should help out.
Also, since the device you're proxying too is the local system, you may want to avoid potential name resolution/NAT confusion by using 127.0.0.1. What you place here has no bearing on the host header received by the server, and the client header is passed through, as long as you've got ProxyPreserveHost On
set:
ProxyPreserveHost On
ProxyPass / http://127.0.0.1/host2/
ProxyPassReverse / http://127.0.0.1/host2/
If that doesn't work, prehaps have host2 serve up some temporary content page to verify that you're hitting the correct vhost.
Side note, you don't want that <Proxy *>
block. It's built for when you're running in ProxyRequests on
mode, and doesn't work as desired for reverse proxies (use <Location>
instead for access control)
Related videos on Youtube
Neo
Updated on September 18, 2022Comments
-
Neo over 1 year
I asked the same question a while ago, but I guess I didn't put my question right. I'm trying to reverse proxy one whole virtual host domain to a subdirectory of another virtual host, something like this http://host2.com -> http://host1.com/host2.
Apache's default site file is this
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName "host1.com" <Directory /srv/www/host1> Options Indexes FollowSymLinks MultiViews AllowOverride None Order deny,allow Allow from all </Directory> DocumentRoot /srv/www/host1 WSGIScriptAlias / /srv/www/host1/apache/django.wsgi </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName "host2.com" ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://host1.com/host2 ProxyPassReverse / http://host1.com/host2 </VirtualHost>
At this moment, the problem is that whenever I go to http://host2.com it shows me http://host1.com instead of http://host1.com/host2. What am I missing? I'm not sure if it should matter, but host1 is hosted using Django with wsgi.
-
Neo about 13 yearsI did have a problem with my servername. Fixed that. But Now I get 403 Frobidden
You don't have permission to access / on this server.
error. -
ravi yarlagadda about 13 years@Neo Try adding a
<Location />
block containing the Order and Allow directives that you have within the<Proxy>
block.