【问题标题】:Nginx Confiuration for reverse proxy with multiple tomcat instances具有多个 tomcat 实例的反向代理的 Nginx 配置
【发布时间】:2016-05-07 07:02:59
【问题描述】:

我是第一次使用 Nginx。

  • 我有两台服务器。服务器一(ip:1.2.3.4) 服务器二(ip: 5.6.7.8)
  • 我已经在服务器 1 上安装了 nginx,在服务器 2 上安装了 Tomcat。
  • 我已成功配置 tomcat 以在不同的端口上运行。我的 tomcat 正在以下端口上运行。

    5.6.7.8:8080
    5.6.7.8:8081
    5.6.7.8:8082

  • 我还在tomcat(每个实例)上部署了我的war文件。

  • 我的nginx配置如下

  • 在 /etc/nginx/conf.d 中创建了一个 default.conf

  • 根据以下链接Nginx Configuration对文件进行修改

    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
        # Make site accessible from http://localhost/
        server_name 1.2.3.4;
    
        location / {
                proxy_pass http://www.example.com;
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rule
        }
    
        location /user/{
                proxy_pass http://5.6.7.8:8080$uri;
    
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rule
        }
    

    }

  • 我在SERVER TWO上部署的War文件名是Example。
    其中包含一个 api /user/login?param1=xyz&param2=abc&param3=mno

  • 当我点击 ip 1.2.3.4 时,它会转到 root(/)。我得到了预期的结果。我得到了 example.com 页面。
  • 但是当我点击 1.2.3.4/user 时,我得到 404 not found。 我期待我的 api 会被调用并且我会得到结果。
  • 如果我点击
    5.6.7.8:8080/Example//user/login?param1=xyz&param2=abc&param3=mno,检查我的 api 是否正常工作。我得到了我期望的正确的 json 结果。
  • 当我点击 1.2.3.4/user 时,我期待同样的结果。但我得到 404。

当我点击 1.2.3.4/user 时,我必须更改哪些内容才能获得结果

谢谢

【问题讨论】:

    标签: tomcat nginx proxy


    【解决方案1】:

    唯一的问题是 try_files 我注释了 try 文件并且一切都正常工作。

    【讨论】:

      猜你喜欢
      • 2021-11-11
      • 2018-05-28
      • 2015-02-12
      • 1970-01-01
      • 2016-01-08
      • 2017-12-01
      • 2020-08-06
      • 2017-08-14
      相关资源
      最近更新 更多