Link to home
Start Free TrialLog in
Avatar of NoOrdinaryRabbit
NoOrdinaryRabbitFlag for Australia

asked on

Using Apache2 to reroute 80 and 443 for various sites

Howdy!

I have an Ubuntu server running Apache2. I would like to use it as a proxy for forwarding traffic from an external IP to different machines hosting different websites.

I can get websites on either 80 or 443 forwarding to different sites but not both at the same time. For instance, if I set up all my virtualhost rules for *.80 the *.443 virtualhost rules don't work.

I'm new to apache2 so I don't really know what I'm doing, just compiling information from various sources.

The default file in /etc/apache2/sites-available/ looks like this:

NameVirtualHost *:80

<VirtualHost *:80>
        ServerAdmin administrator@site1.com
        DocumentRoot /var/www/site1
        ServerName www.site1.com
        ServerAlias site1.com *.site1.com
        ErrorLog /var/log/site1_error.log
        CustomLog /var/log/site1_custom.log common

</VirtualHost>

<VirtualHost *:80>
	DocumentRoot /var/www/site2
	ServerName www.site2.com
	ServerAlias site2.com *.site2.com
	ErrorLog /var/log/site2_error.log
	CustomLog /var/log/site2_custom.log common

</VirtualHost>

<VirtualHost *:80>
	ServerName www.site3.com
	ProxyPreserveHost On
	ProxyPass / http://192.168.1.1/
	ProxyPassReverse / http://192.168.1.1/
	ServerAlias site3.com

</VirtualHost>

NameVirtualHost *:443

<VirtualHost secure.site4.com:443>

	#########################################################
	# SUBDOMAIN STUFF - BEGIN					#
	#########################################################

	ProxyPass	 /subdomain1	https://192.168.1.2/subdomain1/
	ProxyPassReverse /subdomain1	https://192.168.1.2/subdomain1/

	ProxyPass	 /subdomain2	https://192.168.1.3/subdomain2/
	ProxyPassReverse /subdomain2	https://192.168.1.3/subdomain2/

	ProxyPass	 /subdomain3		https://192.168.1.4/subdmain3/
	ProxyPassReverse /subdomain3		https://192.168.1.4/subdmain3/

	#########################################################
	# SUBDOMAIN STUFF - END					#
	#########################################################

</VirtualHost>

<VirtualHost *:443>

        ProxyPass https://address.site2.com https://192.168.1.5/
        ProxyPassReverse https://address.site2.com https://192.168.1.5/

</VirtualHost>

Open in new window


So with the code above site 1, 2 and 3 all work just fine. The HTTPS redirects don't work though. Is there something obvious I'm missing?
ASKER CERTIFIED SOLUTION
Avatar of Member_2_6373554
Member_2_6373554

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial