2016-10-09 38 views
1

嗨我想設置一個nginx作爲我在tomcat服務器上運行的應用程序的反向代理。當我嘗試通過訪問我的應用程序HTTP它工作正常,但是當我嘗試通過訪問HTTPS我得到一個502錯誤Nginx的https反向代理另一個502

這裏如下我的nginx的配置文件

user www-data; 
worker_processes 4; 
pid /run/nginx.pid; 

events { 
    worker_connections 768; 
    # multi_accept on; 
} 


http { 
    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 


    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 


    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log notice; 


    gzip on; 
    gzip_disable "msie6"; 


    rewrite_log on; 

    server{ 
     ssl on; 
     listen 80; 
     listen 443 ssl; 
     server_name myapp.local; 

     ssl_certificate max.local.crt; 
     ssl_certificate_key server.key; 
     #ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; 
       #ssl_ciphers RC3:HIGH:!aNULL:!MD5; 
       #ssl_prefer_server_ciphers on; 
       ssl_session_timeout 5m; 
     keepalive_timeout 60; 



     error_log /var/log/nginx/hybris.log; 
     rewrite_log on; 

     set $my_port 9001; 
     set $my_protocol "http"; 

     if ($scheme = https){ 
      set $myport 9002; 
      set $my_protocol "https"; 
     } 


     location/{  
      if ($http_user_agent ~ "Chrome"){ 
       #just a proof of concept 
       return 301 http://$host/AE/en; 
      } 

      if ($http_user_agent ~ "Firefox"){ 
       #just a proof of concept 
       return 301 http://google.com/; 
      } 
     } 


     location /AE/en { 


      proxy_pass $scheme://10.0.2.2:$my_port; 
      proxy_set_header Host $host; 
     } 


     location ~(?:/..)?/_ui/(.*) { 
      proxy_pass http://10.0.2.2:9001/_ui/$1;  
      proxy_set_header Host $host; 
     } 



    } 

} 
+0

你能告訴什麼錯誤日誌告訴,?爲什麼你不只是https和http server_names? – Satys

回答

1

使用HTTPS時你更改端口以及連接到tomcat服務器的方案 - 這沒有什麼意義。如果後端服務器位於另一個數據中心,而不是本地網絡內,則只能使用https。如果您刪除$ my_port和$ my_protocol定義和改變你的/ AE/EN所在地塊

location /AE/en { 
    proxy_pass http://10.0.2.2:9001; 
    proxy_set_header Host $host; 
} 
-1

我認爲你需要創建兩個服務器部分應該很好地工作。一個用於偵聽端口80,另一個用於監聽https端口453。