Monday, February 8, 2016

mod rewrite - Mod_Rewrite Apache ProxyPass?

I have two websites; OLDSITE and NEWSITE. The OLDSITE has 120 IP Address that it has with it, and the NEWSITE had 5. I want to be able to separate everything from OLDSITE and NEWSITE so they are not tied together but use them on the same linux computer. My current apache setup is this:



Listen 80
NameVirtualHost *




ServerName oldsite.com
ServerAdmin webmaster@oldsite.com

DocumentRoot /var/www/

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all



RewriteEngine on

RewriteCond %{HTTP_HOST} ^([^.]+)\.oldsite\.com$
RewriteCond /home/%1/ -d
RewriteRule ^(.+) %{HTTP_HOST}$1
RewriteRule ^([^.]+)\.oldsite\.com/media/(.*) /home/$1/dir/media/$2
RewriteRule ^([^.]+)\.oldsite\.com/(.*) /home/$1/www/$2




ServerName newsite.com

ServerAdmin webmaster@newsite.com
DocumentRoot /var/newsite/

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all




RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.newsite\.com$
RewriteCond /home/%1/ -d
RewriteRule ^(.+) %{HTTP_HOST}$1
RewriteRule ^([^.]+)\.newsite\.com/media/(.*) /home/$1/dir/media/$2
RewriteRule ^([^.]+)\.newsite\.com/(.*) /home/$1/www/$2






ServerName panel.oldsite.com
ProxyPass / http://panel.oldsite.com:10000/
ProxyPassReverse / http://panel.oldsite.com:10000/


allow from all







ServerName panel.newsite.com
ProxyPass / http://panel.newsite.com:10000/
ProxyPassReverse / http://panel.newsite.com:10000/


allow from all





I want to be able to access anything that is newsite.com and have it go to the /var/newsite unless their is a home directory...and then if its panel.newsite.com I want it to automatically do a proxypass to panel.newsite.com:10000... With this setup, it works perfect for oldsite.com.... both the proxy and the webpages... However, having the Virtualhost set to newsite.com renders the proxypass worthless. If I change the Virtualhost for the newsite.com to a wildcard, the proxypass will work but anything thats a subdomain of newsite.com won't work. so newsite.com will work, but www.newsite.com will not load correctly.



I am assuming that when everything is wildcarded, then the ServerName somewhat acts like a RewriteCond and actually just applies the stuff to that URL. It uses the Virtualhost * (oldsite.com) and lets ANYTHING.oldsite.com work, but the second virtualhost * (newsite.com) only newsite.com will work... www.newsite.com will not. If I change the order of them, the opposite is true. So apparently it doesn't like me using 2 wildcards...



I tried just making the Servername *.newsite.com .......but that would be too easy. I am not sure what I can do to do what I want? Perhaps I should make the ProxyPass included in the VirtualHosts and use something like:



RewriteCond     %{HTTP_HOST}            ^panel\.newsite\.com$   [NC]

RewriteRule ^(.*)$ http://panel.newsite.com:10000/ [P]
ProxyPassReverse / http://panel.newsite.com:10000/


but that doesnt seem to want to login to webmin, it loads the login page but isnt working how the ProxyPass & ProxyPassReverse does.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...