How to send request to proxy pass url based on server name in nginx?

g13 asked:

I have subdomains a.domain.com and b.domain.com. Below is my configuration:

server {
 listen 80;
 server_name a.domain.com b.domain.com;

 location / {
   .
   .
   .
   proxy_pass http://example.com/$server_name/;
 }
}

This is giving error like

“no resolver defined to resolve http://example.com/…”

Is it possible to send proxy pass url based on server name or am I missing something?

My answer:


You’re trying to proxy requests to example.com. But you haven’t defined example.com as an upstream, so nginx treats it as a hostname to look up and connect to. But you don’t have a DNS resolver defined anywhere.

To fix the problem, do one of those two things.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.