【问题标题】:Nginx configuration doesn't work properly on TomcatNginx 配置在 Tomcat 上无法正常工作
【发布时间】:2020-06-11 01:33:31
【问题描述】:

您好,我在将 nginx 配置为代理服务器以将请求重定向到我的 tomcat 服务器时遇到问题。我有 3 台 tomcat 服务器在不同的机器和不同的端口上运行,就像这样

192.168.51.115:8115
192.168.51.120:8120
192.168.51.130:8130

现在我想配置 nginx 像这样依次将请求传递给我的三台服务器

www.example.com/app1
www.example.com/app2
www.example.com/app3

真实IP:123.123.123.123

这是我在 - site-enabled 下的配置

server {
        listen 80;
        server_name example.com www.example.com;

        location /app1 {
             proxy_pass "http://192.168.51.115:8115";
        }

        location /app2 {
                proxy_pass "http://192.168.51.120:8120";
        }

        location /app3 {
                proxy_pass http://192.168.51.130:8130;
        }
}

注意:当我将位置指令放置在 / 上时,它可以工作,但不适用于 /*,如 app1、app2 或 app3

【问题讨论】:

    标签: nginx tomcat reverse-proxy nginx-reverse-proxy


    【解决方案1】:

    您可以尝试在您的位置块中使用 ^~ 作为修饰符吗?

    喜欢

    server {
            listen 80;
            server_name example.com www.example.com;
    
            location ^~ /app1 {
                 proxy_pass "http://192.168.51.115:8115";
            }
    
            location ^~ /app2 {
                    proxy_pass "http://192.168.51.120:8120";
            }
            location ^~ /app3 {
                    proxy_pass http://192.168.51.130:8130;
            }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-02-26
      • 1970-01-01
      • 2013-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 2013-09-24
      相关资源
      最近更新 更多