5

I have a virtual machine in azure running three self hosted applications (not hosted in IIS) on three different ports.

I can access them at the urls below:

  • my-server.cloudapp.azure.com:8080
  • my-server.cloudapp.azure.com:8081
  • my-server.cloudapp.azure.com:8082

I've purchased a domain name (my-server.company.com) and want to create three subdomains pointing to each respective applications

  • application-1.my-server.company.com
  • application-2.my-server.company.com
  • application-3.my-server.company.com

My first thought is to install IIS on the virtual machine and setup a reverse proxy using URL Rewrite on the default website as mentioned in this article (http://weblogs.asp.net/owscott/creating-a-reverse-proxy-with-url-rewrite-for-iis).

So in this scenario, I would setup CNAME records for each of the sub-domains to point to my-server.cloudapp.azure.com and then configure the reverse proxy to forward to the different ports (8080, 8081, 8082) based on the host header.

Is this possible / the best way to go about this?

The second question is once I get this working, how can I add ssl?

Would each sub-domain need its own ssl certificate, in which case how can this work with the setup above (there are no iis websites to bind each certificate to). Or could I just use a certificate for my-server.company.com and then offload at the reverse proxy?

4
  • 1
    Just to be completely unhelpful and whiny: a CNAME can't point to "my-server.cloudapp.azure.com:80", because CNAME's don't have port numbers. I think you meant a CNAME to "my-server.cloudapp.azure.com"
    – user3919
    May 3, 2016 at 16:11
  • 1
    yep, your right,. I have updated the question
    – kimsagro
    May 3, 2016 at 23:00
  • Do you need to use IIS or might you consider an alternative reverse proxy? Caddy Server works on Windows, is a breeze to use, offers Let'sEncrypt for free SSL on your domains and will also work as a nice reverse proxy.
    – AM Douglas
    May 9, 2016 at 12:58
  • Happy to use whatever works, can Caddy reverse proxy based on host header?
    – kimsagro
    May 10, 2016 at 0:12

1 Answer 1

1

Solution

I created CNAME dns records as follows:

CNAME | application-1 | my-server.cloudapp.azure.com
CNAME | application-2 | my-server.cloudapp.azure.com
CNAME | application-2 | my-server.cloudapp.azure.com

Then on the azure vm I run Caddy (a HTTP/2 web server with automatic HTTPS) with the following Caddyfile:

application-1.my-server.company.com {
    proxy / localhost:8080 {
        proxy_header Host {host}
    }
}

application-1.my-server.company.com {
    proxy / localhost:8081 {
        proxy_header Host {host}
    }
}

application-1.my-server.company.com {
    proxy / localhost:8082 {
        proxy_header Host {host}
    }
}

The beauty of this, is the first time Caddy runs, it automatically enables HTTPS for all your sites (using autogenerated certs from Let's Encrypt) and will also redirect all HTTP requests to their HTTPS equivalent.

This setup also meant I didn't have to install IIS on the VM.

NOTE: You need to add an inbound firewall rule for ports 80 and 443 for Caddy to work

1
  • Wow. Thanks for letting me know about Caddy, I struggled with ISS but now I have a reverse proxy with SSL enabled for both my subdomains in literally 10 minutes. Big up
    – StackHola
    Aug 10, 2021 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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