【问题标题】:Nginx reverse proxy destination from request url来自请求 url 的 Nginx 反向代理目的地
【发布时间】:2018-06-20 03:30:05
【问题描述】:

我在配置 Nginx 时遇到问题:

  • 来自请求 url 的目标服务器的反向代理
  • 端口可以是默认端口 (80),但如果这也可以来自请求 url,那就太好了
  • 然后我想调用http://nginxserver/destinationserver 的行为

nginx 会调用destinationserver(取自请求url,位置不固定)

我尝试过类似的方法,但它不起作用

location  ~^\/([a-zA-Z0-9]+)\/([0-9]+)\/([a-zA-Z0-9]+) {
proxy_pass http://$1:$2/$3;
}

我需要上述行为,因为我们有来自一台服务器的静态 VPN,我可以在其中拥有 nginx 和其他一些远程设备。这些设备中的每一个都有一个网络服务器,从默认端口 80 显示设备状态。问题是,只有从服务器内部(有 VPN),我们才能访问每个远程设备,所以我正在尝试使用 Nginx 启用反向代理来从服务器外部访问设备。

感谢您的帮助

【问题讨论】:

    标签: nginx nginx-reverse-proxy


    【解决方案1】:

    解决方案:

    这是我找到的解决方案:

    location  ~ "/go/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(.+)$" {
        proxy_pass http://$1:80$2;  
        sub_filter "<head>" "<head><base href=\"${scheme}://${host}/go/$1/\">";     
        sub_filter_once off;    
        sub_filter_types application/json application/x-javascript;     
        sub_filter '"/flash/' '"/go/$1/flash/';     
        sub_filter '"/rom/' '"/go/$1/rom/'; 
    }
    

    例如,我可以使用以下网址:http://myproxyserver/go/192.168.0.100/ 我得到了 192.168.0.100 的响应 throw the nginx 反向代理。

    【讨论】:

      猜你喜欢
      • 2019-06-20
      • 2018-05-07
      • 1970-01-01
      • 2017-11-17
      • 1970-01-01
      • 1970-01-01
      • 2020-05-12
      • 2013-07-16
      • 2021-11-09
      相关资源
      最近更新 更多