Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

So we wish to host some pages on a new server with apache2, and embed some of our old content & functionality from another server with lighttpd in an iframe. I'm looking at this configuration from the apache docs (http://httpd.apache.org/docs/2.2/vhosts/examples.html#page-header) under "Using Virtual_host and mod_proxy" together.

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

The only issue is that I want to proxy only on a subdomain, or even better, if I can keep the top domain and proxy only if the url contains a particular path ie. "/myprocess.php". So in essence the DNS will point to the apache2 as the "master router".

share|improve this question

2 Answers 2

You're probably best doing this using a setup of 3 VirtualHost declarations.

The first, becomes a default catch-all for any name that has not been specified, and you could have an index.php in the /var/www/default/ that either returns a blank page or an HTTP 404 response etc:

<VirtualHost *:80>
  ServerAdmin webmaster@example.com
  ServerName hostname.example.com
  DocumentRoot /var/www/default
  DirectoryIndex index.php index.html index.htm
  ErrorLog /var/log/httpd/default/error_log
  TransferLog /var/log/httpd/default/access_log
</VirtualHost>

The second, becomes your main new website using the domain www.example.com:

<VirtualHost *:80>
  ServerAdmin webmaster@example.com
  ServerName www.example.com
  DocumentRoot /var/www/default
  DirectoryIndex index.php index.html index.htm
  ErrorLog /var/log/httpd/newsite/error_log
  TransferLog /var/log/httpd/newsite/access_log
</VirtualHost>

The third, works as a proxy to your old website using the subdomain oldsite.example.com:

<VirtualHost *:80>
  ServerAdmin webmaster@example.com
  ServerName oldsite.example.com
  ProxyPreserveHost On
  ProxyPass / http://192.168.111.2/
  ProxyPassReverse / http://192.168.111.2/
  ErrorLog /var/log/httpd/oldsite/error_log
  TransferLog /var/log/httpd/oldsite/access_log
</VirtualHost>
share|improve this answer

You can use mod_rewrite to set rules about which URLs should be served via reverse proxy. There is documentation about it on the Apache website: http://httpd.apache.org/docs/2.2/rewrite/proxy.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.