0
votes

My current setup is like this. I have a registered domain name. Through my domain provider I have pointed my domain to a dynamic IP address. So mysite.com points to 97.89.120.x

I have dd-wrt router and it is keeping my dynamic IP updated and port forwarding all port 80 and 443 request to my apache server IP of 192.168.121.50 ( Nothing real crazy here)

My apache server redirects all port 80 request to port 443 cat /etc/apache2/sites-available/default

<VirtualHost *:80>
    RewriteEngine on
    ReWriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

cat /etc/apache2/sites-available/default-ssl

<VirtualHost _default_:443>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mycloud
</VirtualHost>

This all works like a champ and is very straight forward.

I want to add a subdomain of cloud.mysite.com. So that mysite.com and cloud.mysite.com both point to the same dynamic IP 97.89.120.x From my dd-wrt router I am port forwarding all port 80 and 443 request to a new server in my environment 192.168.121.60

I want the apache server on this new host to host mysite.com and to forward request for cloud.mysite.com to the other server 192.168.121.50 and be redirected to https / ssl / ports 443.

So how exactly do I setup the virtual server to do this? I have tried similar to this without success.

NameVirtualHost *
    <VirtualHost *:80>
    ServerName www.mysite.com
    DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
    ServerName www.cloud.mysite.com
    ServerAlias 192.168.121.50
    DocumentRoot /var/www/mycloud
</VirtualHost>

How can I redirect the subdomain to a different server and get this to work?

2

2 Answers

0
votes

You have a wrong understanding of virtual hosts. The purpose of vhosts is to host multiple sites on a single webserver. It is not impossible to do this with your approach, but in the case that you have several webservers and services that you want to publish to the www in one domain, you will organize this in another way.

You can do this by DNS, Gateway, Reverse Proxing, Routing and maybe other approaches.

I suggest to find an approach where the ddwrt router will organize the requests and hand them to the desired webserver.

On ddwrt, just as example for a reverse proxy and loadbalancer, you can do this with Pound: http://www.dd-wrt.com/wiki/index.php/Pound

Please let me know if you have further questions. I will edit my post then. But this is from this point a question for serverfault and not for stackoverflow.

0
votes

You will need to use 192.168.121.60 as a proxy of 192.168.121.50. But this may not be the best/smart way to achieve this. Proxying a web server for another ??

You already have setup for cloud.mysite.com on 192.168.121.60. Using mod_proxy_balancer ,this will look something like below.

<VirtualHost *:80>
  ServerName www.cloud.mysite.com
  ServerAlias cloud.mysite.com

  ProxyRequests Off
 <Proxy balancer://mycluster>
   BalancerMember http://192.168.121.50
 </Proxy>
 ProxyPass / balancer://mycluster

</VirtualHost>

The best way as pointed out by @LukasF is to have both the sites hosted on a single web server.
Hope that helps!