
标题一句话说不清楚,需求是这样的,假设有 a.com 的域名,希望 nginx 收到 ccc.bbb.a.com 的 host 能够反代到 ccc.bbb 这个 host 去,找了一下资料,没有找到怎么配置
想要类似这样的配置:
server_name ${child}.a.com; location / { proxy_pass http://${child}:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } 1 joesonw 2020 年 7 月 23 日 你这个要配合 dns. |
2 binbinyouliiii OP @joesonw #1 已经将 *.a.com 的域名都解析到了 这个 IP,Nginx 这边不知道怎么设置 |
3 suman 2020 年 7 月 23 日 配置 hosts |
4 ghostwwg 2020 年 7 月 23 日 @binbinyouliiii dns 有种记录叫做 cname |
5 aapeli 2020 年 7 月 23 日 via iPhone 4 、匹配正则表达式: server { listen 80; server_name ~^(?.+)\.howtocn\.org$; ... } |
6 binbinyouliiii OP @ghostwwg #4 我是要做动态的,是不只有 ccc.bbb.a.com 这一个域名 |
7 aapeli 2020 年 7 月 23 日 via iPhone nginx server_name 字段支持通配符和正则表达式 |
9 takemeaway 2020 年 7 月 23 日 这种跳转干嘛走 nginx 呢,直接入口就行了 |
10 joesonw 2020 年 7 月 23 日 @binbinyouliiii 不要写 server_name, 然后 rewrite 应该是只可以改写 path. 你这个用 nginx lua 倒是可以实现. |
11 rrfeng 2020 年 7 月 23 日 |
12 GM 2020 年 7 月 23 日 nginx 问题问我就对了。 server { listen 80; server_name ~^(?<subdomain>.+)\.hottocn\.org$; location / { proxy_pass http://backend_server/; proxy_set_header Host $subdomain.ccc.com; } #或者 location / { proxy_pass http://$subdomain.ccc.com/; proxy_set_header Host $subdomain.ccc.com; } } |