微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

dynamicproxy_pass到$ var与nginx 1.0

我正在尝试根据环境variables将请求代理到不同的目标。 我的方法是将目标url放入自定义variables$ target中,并将其传递给proxy_pass。

但是使用proxy_pass的variables似乎不起作用。 这个简单的configuration会导致Nginx的“502 Bad Gateway”响应。

server { listen 8080; server_name myhost.example.com; access_log /var/log/Nginx/myhost.access.log; location /proxy { set $target http://proxytarget.example.com; proxy_pass $target; } }

没有variables的同样的configuration工作:

server { listen 8080; server_name myhost.example.com; access_log /var/log/Nginx/myhost.access.log; location /proxy { proxy_pass http://proxytarget.example.com; } }

是否真的不可能这样使用proxy_pass或者我只是做错了什么?

如何在Windows上查看代理设置?

设置执行客户端证书authentication到远程服务器的代理

Nginx反向代理之后的端口3000上可以访问nodejs应用程序

在Cent OS 7上,forticlientsslvpn不能与代理一起使用

docker工人组成的粘滞会议的规模

在代理传递url中的Nginx尾部斜杠

在Android / Linux上设置透明TCP代理时遇到问题

编写用于Windows的SNMP代理程序:SnmpAPI.Lib或MgmtAPI.lib?

Apache,Tomcat,端口80,8080和其他东西的组合

如何testingNginx代理超时

我最近偶然发现了这个需求,发现为了在proxy_pass目的地中使用变量,你需要设置一个解析器作为你的error.log最有可能包含像no resolver defined to resolve ...东西no resolver defined to resolve ...

在我的情况下解决方案是设置以下使用谷歌DNS解析:

location ~ /proxy/(.*) { resolver 8.8.8.8; proxy_pass http://$1; }

在你的情况下,这应该工作:

location /proxy { resolver 8.8.8.8; set $target http://proxytarget.example.com; proxy_pass $target; }

有关Nginx和动态proxy_pass更多信息,请访问: http : proxy_pass

偶然发生同样的问题

proxy_pass没有解决我的变数,直到我们发现我们的DNS服务器有问题

可以用这个cmd顺便检查一下

nslookup your-domain your-dns-ip

location / { if ($args ~ "^url=(.+)") { #gets the "url" get parameter set $key1 $1; proxy_pass $key1;#use the parameter as proxy address } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐