大网数据广告活动
网站运营与故障问答

IIS sub-domain reverse proxy based on host name

· 52CE 我爱测

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-se…

问题原文

原帖链接 · kimsagro · CC BY-SA 3.0

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?

已采纳解答

原帖链接 · kimsagro · CC BY-SA 3.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。