Welcome! Log In Create A New Profile

Advanced

Help dynamically building url for proxy_pass

Posted by mikeyb7 
Help dynamically building url for proxy_pass
July 05, 2016 09:43AM
Hi everyone,

I'm hoping someone can help me with the following problem:

I'm trying to build up the url used in proxy_pass so it can handle multiple brands and team names in our dev environment. My nginx.conf file looks like this:

events {
worker_connections 1024;
}

http {
server {
listen 80;
server_name ~^(www\.)?(?<brand>\w+)\.(?<team>\w+)\..*$;

location / {
proxy_set_header Host www.$brand.$team.dev;
proxy_pass http://vmware-$team.dev;
}
}
}

The reason we want to do this is so multiple teams can be routed through to their own INT server.

An example request could be www.brandA.teamB.dev and i want to rout this through to http://vmware-teamB.dev.

If i hardcode 'http://vmware-teamB.dev' as the proxy_pass value it works, but when trying to use the variable I get the following error:

[error] 5#5: *1 no resolver defined to resolve vmware-teamB.dev, client: 192.168.99.1, server: ~^(www\.)?(?<brand>\w+)\.(?<team>\w+)\..*$, request: "GET / HTTP/1.1", host: "www.brandA.teamB.dev"
192.168.99.1 - - [05/Jul/2016:13:39:58 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
2016/07/05 13:39:58 [error] 5#5: *1 no resolver defined to resolve vmware-teamB.dev, client: 192.168.99.1, server: ~^(www\.)?(?<brand>\w+)\.(?<team>\w+)\..*$, request: "GET /favicon.ico HTTP/1.1", host: "www.brandA.teamB.dev", referrer: "http://www.brandA.teamB.dev/"
192.168.99.1 - - [05/Jul/2016:13:39:58 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://www.brandA.teamB.dev/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"

Can anyone please help? Am i allowed the build up a url like this?

Many thanks,
Mike
Re: Help dynamically building url for proxy_pass
July 05, 2016 01:58PM
"no resolver defined to resolve vmware-teamB.dev"

You need to add your 'names' to your DNS and add a resolved value to nginx.conf.

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 92
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready