I want to use nginx for a dynamic proxy. Here are the rules:
/os-abc/... to http://abc.a.domain.com:1234/...
/os-xxx/... to http://xxx.a.domain.com:1234/...
/os-yyy/... to http://yyy.a.domain.com:1234/...
...
So I write a proxy rule in nginx.conf.
location ~ ^/os-(.*)/ {
proxy_pass http://$1.a.domain.com:1234/;
add_header Cache-Control 'public, max-age=99999999999, immutable';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
But it does NOT work (get 502). nginx version: nginx/1.28.2
My Question
-
How could I see what
http://$1.a.domain.com:1234/becomes? -
How to let it work?
-
Why is this simple requirement so hard to implement?
Progress
I add resolver directive to the conf file. But the error log shows: hdd1 could not be resolved (3: Host not found). It seems nginx force to resolve $1 instead of β$1.a.domain.comβ.