【问题标题】:how to reverse proxy via nginx a specific url?如何通过 nginx 反向代理特定的 url?
【发布时间】:2014-06-09 08:53:09
【问题描述】:

我有一个在http://localhost:8080 运行的服务器,我希望该服务器的特定 url 由 nginx 代理。

例如,我只想将 http://localhost:8080/test/(.*) 反向代理到 http://localhost/test/(.*)

我正在将另一台服务器代理到http://localhost/

【问题讨论】:

    标签: nginx reverse-proxy


    【解决方案1】:

    如果只是一个简单的location 块呢?

    server {
        # ... other stuff
    
        location /test/ {
            try_files $uri @testproxy;
        }
    
        location @testproxy {
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header X-Forwarded-Host $server_name;
            proxy_set_header X-Real-IP $remote_addr;
            # all your params
        }
    }
    

    【讨论】:

      【解决方案2】:

      我以某种方式做到了,并且成功了。无论如何,感谢您的评论。 :)

      server {
          listen 80;
          # ... other stuff
      
          upstream backend1 {
              server 127.0.0.1:8080;
          }
      
          location /test/ {
              proxy_pass_header Server;
              proxy_set_header Host $http_host;
              proxy_redirect off;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Scheme $scheme;
              proxy_pass http://backend1/test/;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-28
        • 2019-10-30
        • 1970-01-01
        • 2020-05-12
        相关资源
        最近更新 更多