答案比这简单。只需获取具有子域的子字符串,并将其用作proxy_pass的参数即可:
server { # this matches every subdomain of domain. server_name .domain; location / {set $new_request_uri ""; set $subdomain ""; if ($host ~* "^(.+).domain$") { set $subdomain $1; # lets assume there are args... set $new_request_uri "$request_uri&subdomain=$subdomain"; } # if there are no args add a question mark and the subdomain argument if ($args = '') { set $new_request_uri "$request_uri?subdomain=$subdomain"; } proxy_pass http://127.0.0.1:8080$new_request_uri; } }我考虑了带或不带参数的请求。我认为这可以解决您的问题。



