网上搜了半天没啥有效信息,询问一下万能的 v 友
比如绑定*.domain.com 的域名,如果想加反向代理的话,一般写法是
server {
listen 80;
server_name ~^(?<subdomain>.+)\.m\.domain\.com$;
location /{
proxy_pass http://xxx/;
proxy_set_header Host $host;
}
}
这里利用 /做路由,但是如果我想要 a.domain.com 和 b.domain.com 分别代理不同的网页,要怎么识别 a 和 b 的部分呢?
1
dorothyREN 115 天前
if 判断一下就行吧
|
3
julyclyde 114 天前
虽然能实现,不过还是建议重新梳理一下需求
|
4
dode 114 天前
server {
listen 80; server_name a.domain.com; location /{ proxy_pass http://xxx/; proxy_set_header Host $host; } } server { listen 80; server_name b.domain.com; location /{ proxy_pass http://xxx/; proxy_set_header Host $host; } } server { listen 80; server_name ~^(?<subdomain>.+)\.m\.domain\.com$; location /{ proxy_pass http://xxx/; proxy_set_header Host $host; } } |
![]() |
5
xuanbg 114 天前
为什么不写成两个 server 呢? 4 楼那样?
|
![]() |
6
chinni 114 天前 via Android
sniproxy 不就行……
|
![]() |
7
rekulas 114 天前
location 里面可以写 if 判断 一个 server 也可以
if ( $host = 'a.domain.com' ){ proxy_pass https://www.baidu.com:443; } |
![]() |
8
xiang0818 114 天前
最好用不同的域名配置
|
![]() |
9
wxyrrcj 114 天前
*.baidu.com
|
10
FrankAdler 114 天前 via iPhone
二楼 map 正解
|
11
salmon5 113 天前
#4 的方法无疑是最好的,大道至简;
map 弄复杂了,map 适合更复杂的场景。 |