背景:
1.美國團隊開發的web程序部署在一臺服務器上,老舊的GlassFish2.x,還是Windows,以下稱App1。
2.我們新開發的web程序部署在另一臺服務器上,Ubuntu 12.04 server,新版本的GlassFish3.x,以下稱App2。
問題:
要想辦法把這兩個程序僞裝成一個站點,這樣可以解決兩個問題:
1.認證問題,瀏覽器先從App1登陸,保存cookie。然後再訪問App2的時候,會將cookie發過來,App2通過解析cookie內的token,來進行用戶身份認證,如果無token,或者無cookie,自動轉向App1要求登陸。否則拿到token後,通過server端調用App1的驗證API來檢查該用戶session是否過期。
2.同時支持HTTP/HTTPS,因爲登陸等敏感請求需要加密。
來一張圖,對理解我的話比較有幫助:
如何配置呢,將配置寫在一個獨立的conf文件裏面,包括兩部分,一部分配置HTTP.
- server {
- listen 80;
- server_name 192.168.1.10;
- access_log /opt/agol_http.log my_log;
- location ^~ /home {
- proxy_pass http://192.168.1.11;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- location ^~ /sharing {
- proxy_pass http://192.168.1.11;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- location /geoflow {
- proxy_pass http://192.168.1.10:8081/flow;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- }
HTTPS也單獨配置一個Server
- # HTTPS server
- server {
- listen 443 ssl;
- ssl_certificate /usr/nginx/conf/server.crt;
- ssl_certificate_key /usr/nginx/conf/server.key;
- server_name 10.112.18.178;
- access_log /opt/agol_https.log my_log;
- location / {
- proxy_pass https://192.168.1.11;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- }
最後在nginx.conf的http設置裏面加上
include agol.conf;
即可。