When using proxy_pass, can /etc/hosts be used to resolve domain names instead of “resolver”?

前端 未结 2 850
再見小時候
再見小時候 2020-12-07 21:38

Can /etc/hosts be used instead of resolver when using proxy_pass?

I need to perform a proxy_pass to the same nginx

2条回答
  •  甜味超标
    2020-12-07 21:49

    A workaround is to use Nginx map, in order to copy the /etc/hosts content.

    map $wanted_host $wanted_host_ip
    {
        default 127.0.0.1;
        b.dev.local X.X.X.X;
        a.dev.local X.X.X.X;
    }
    
    server
    {
        listen              80;
        server_name         ~^(?P[0-9]+?)-(?P.+?)\.HOSTNAME$;
    
        location /
        {
            proxy_pass http://$wanted_host_ip:$wanted_port;
    
        }
    }
    

    This will map wanted_hostto wanted_host_ip , like a resolver.

提交回复
热议问题