I have a host machine running Ubuntu Server 14 with quiet a few guest VMs also running Ubuntu Server 14.

I have two of those VMs running web servers. Port 80 is forwarded to the machine with the standard site (controlpanel.mysite.com) and I have another VM running a site that requires 443 (cloud.mydomain.com). 443 is setup in the router to forward to the VM and redirect is enabled on the machine. What I would like if possible, is to have port 80 redirected to that machine IF it matches the name that is incoming. When people put in http://cloud.mydomain.com they are taken to port 80 (controlpanel.mysite.com) which isn't the site I want them to view. I want it to go right to cloud.mydomain.com.

I've tried following the example in this site https://httpd.apache.org/docs/trunk/vhosts/examples.html with no luck. Any ideas?

  • 1
    Is there an actual requirement to have these on separate virtual machines? If you only split them on to virtual machines to be able to run multiple websites, then put them all onto the main host and use VirtualHosts to separate them by hostname like you're requesting. That's what Virtual Hosts in Apache are for. – Safado Feb 7 '16 at 22:31
  • Not really. I guess I could put the control panel on the cloud server if that is the only way. – Medic303 Feb 8 '16 at 1:36

Considering there's no requirement to have all of these web sites on separate Virtual machines, configure Apache on your host to serve out all of them using the VirtualHost directive.

You'll have one <VirtualHost *:80> for controlpanel.mysite.com, one for cloud.mydomain.com and then a <virtualHost *:443> for cloud.mydomain.com on HTTPS. The DNS for all of these domains should resolve to the IP of your host.

When requests come in to Apache, it'll check the protocol (http / https), then the domain name being requested and serve up the appropriate website accordingly.

| improve this answer | |

Assuming you want to keep the web servers on separate VMs you need a device that can choose which VM to send the traffic based on the HTTP Host header. Simple IP-level port forwarding cannot do this. Most reverse proxies can. E.g., varnish can. You'll need another VM running varnish or if you run it on one of these 2 VMs you'll need to have it listen on another port. E.g., have it listen on port 8080 and port forward 80 to 8080.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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