2016-05-07 76 views
1

我第一次使用Nginx。Nginx配置多个tomcat实例的反向代理

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

    5.6.7.8:8080
    5.6.7.8:8081
    5.6.7.8:8082

  • 我也部署在tomcat的我的战争文件(每个实例)。

  • 我已经如下

  • 在/etc/nginx/conf.d创建default.conf配置我的nginx

  • 按照下面的链接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 TW上的War文件的名称O是例子。
    其包含API /user/login?param1=xyz&param2=abc&param3=mno

  • 当我打IP 1.2.3.4,它进入根(/)。我得到了预期的结果。我正在获取example.com页面。
  • 但是,当我点击1.2.3.4/user,我得到404没有找到。 我期待着我的API会被调用,我会得到结果。
  • 要检查我的API是否工作或没有如果我打
    5.6.7.8:8080/Example//user/login?param1=xyz &参数2 = ABC &参数3 = MNO。我得到了我期待的正确的json结果。
  • 而当我打1.2.3.4/user。但我得到404

我期待这个相同的结果什么都事情我必须为了得到时,我打的结果改变1.2.3.4/user

谢谢

回答

1

唯一的问题是在try_files我评论的尝试文件和每一件事情是否正常工作。