2016-05-07 122 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我評論的嘗試文件和每一件事情是否正常工作。