Não testado, mas dê uma chance a isso:
server_name ~^(www\.)?[^.]+.example.org$;
if ($host ~* ^(www\.)?([^.]+).example.org$) {
set $subdomain $2;
}
location / {
proxy_pass http://example.org:8080/$subdomain;
}
Eu quero fazer algo como:
server_name ~^(www\.)?(?<subdomain>[^.]+).example.org$;
location / {
proxy_pass "http://example.org:8080/$subdomain";
}
Testado e funcionando:
server_name "~(.*).dummy.local";
location / {
echo $1;
}
Ao solicitar foo.dummy.local
, ele exibirá foo
.
curl -vvv foo.dummy.local
* Rebuilt URL to: foo.dummy.local/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to foo.dummy.local (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: foo.dummy.local
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.10.3
< Date: Thu, 20 Sep 2018 09:15:54 GMT
< Content-Type: application/octet-stream
< Transfer-Encoding: chunked
< Connection: keep-alive
<
foo
* Curl_http_done: called premature == 0
* Connection #0 to host foo.dummy.local left intact
Tags nginx