Welcome! Log In Create A New Profile

Advanced

How to make nginx start/reload if it encounters dns error while looking up fqdn in server directive

Posted by gurumisc 
I have several nginx services configured on my system. Suppose one of these services is configured with upstream block and with server directive pointing to fqdn.

With this configuration files, when nginx starts up or reloads config file and if it's not able to resolve fqdn, then it wouldn't even start or reload rest of the configuration data. As a result, all my services are down just because one service encounters an error.

With set directive and using a variable in proxy_pass directive, you can make nginx to resolve the fqdn only during request proxying. But in my case, I have a upstream block and using server directive to specify fqdn. So that solution will not work for me. So is there a way to make nginx still go ahead with the configuration and start even when it encounters DNS error or make nginx delay DNS resolution only when the http request arrives?


As an example, here is the sample block inside a conf file

upstream ustreamtest{

server test-server.com:80 ;
}

server {
server_name test ;
listen 192.168.150.89:802 ;
resolver 10.0.0.5 ;
proxy_bind 192.168.150.87;

location / {
set $test "ustreamtest";
proxy_pass HTTP://$test;

proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;

include /usr/local/nginx/conf/proxy.conf ;
proxy_redirect off;
}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 103
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready