Nginx proxy_pass with $remote_addr

后端 未结 4 1012
时光说笑
时光说笑 2020-12-23 13:43

I\'m trying to include $remote_addr or $http_remote_addr on my proxy_pass without success.

The rewrite rule works

location ^~ /freegeoip/ {  
  rewri         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 14:16

    It seems a bit strange that nginx is failing to resolve the domain name at runtime rather than at configuration time (since the domain name is hard coded). Adding a resolver declaration to the location block usually fixes dns issues experienced at runtime. So your location block might look like:

    location ^~ /freegeoip/ {
      #use google as dns
      resolver 8.8.8.8;
      proxy_pass http://freegeoip.net/json/$remote_addr;
    }
    

    This solution is based on an article I read a while back - Proxy pass and resolver. Would be worth a read.

提交回复
热议问题