【问题标题】:Reverse proxy to direct different name to different ports反向代理将不同的名称定向到不同的端口
【发布时间】:2020-02-28 08:20:27
【问题描述】:
我们有 2 个 DNS 名称(称为 D1 和 D2)指向同一个 IP 地址(称为 A)。在 A 处,不同端口上有 2 个网络服务器(例如 8081 和 8082)。我需要配置 2 个名称指向 2 个网络服务器,例如 D1 指向 A:8081,D2 指向 A:8082。我认为这很简单,但无法弄清楚如何将 Apache 或 Nginx 配置为反向代理来执行此操作。 (这只是为了让用户不必输入端口号。)
【问题讨论】:
标签:
apache
nginx
reverse-proxy
【解决方案1】:
您有两个 DNS 名称,因此将在 Nginx 中作为两个 server 块和不同的 server_name 语句实现。详情请见this document。
例如:
server {
server_name d1.example.com;
location / {
proxy_pass http://127.0.0.1:8081;
}
}
server {
server_name d2.example.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}