I want to use $host variable in proxy_pass. If directly hardcode
Hostname in proxy_pass it is working fine. But if I use variable $host
it is giving me “502 Bad Gateway”
server {
listen 80;
server_name “”;
location / {
proxy_pass https://cds.hh.net; //working fine
proxy_pass https://$host; //gives error.
And $host value is same like above hostname “cds.hh.net”
proxy_redirect off;
}
}
Thanks for help.
Posted at Nginx Forum:
Hi,
I want to use $host variable in proxy_pass. If directly hardcode
Hostname in proxy_pass it is working fine. But if I use variable $host
it is giving me “502 Bad Gateway”
Check your error.log, it will tell you that you’re missing “resolver”.
Best regards,
Piotr S. < [email protected] >
what should I specify in resolver?
Posted at Nginx Forum:
Hi,
resolver 127.0.0.1;
(…)
375#0: recv() failed (111: Connection refused) while resolving,
resolver: 127.0.0.1:53
That’s because you don’t have DNS resolver running on the localhost.
Point nginx to the DNS resolver you’re using (from /etc/resolv.conf).
Best regards,
Piotr S. < [email protected] >
I tried this,
server {
listen 80;
server_name “”;
location / {
resolver 127.0.0.1;
proxy_pass https://$host; //gives error. And $host value is same like
above hostname “cds.hh.net”
proxy_redirect off;
}
}
but still not working. If I check error log it says,
375#0: recv() failed (111: Connection refused) while resolving,
resolver: 127.0.0.1:53
Thanks for your help.
Hiren
Posted at Nginx Forum:
Thanks. It is working now.
Posted at Nginx Forum: