1.1 準備階段
1、 程式代碼http和https協定跳轉編寫完成
2、 使用resin、tomcat能夠正常啟動
3、 安裝nginx
4、 修改nginx配置檔案
1.2 程式代碼http和https協定跳轉說明
我們以前通常使用JavaScript的window.location、$(this).attr(“href”,”位址”)方法作為頁面跳轉。通常情況下,以上的那些跳轉的那方法是可以實作的,但是,如果使用以上的方法轉跳到https協定是不可取的。
那麼現在如何從http跳轉到https協定,我的方法是使用window.location這個方法進行轉跳的,書寫方式為:window.location=https://IP:端口/位址。
同樣的,從https跳轉到http也是同樣的方法,書寫方式為:window.location=http://IP:端口/位址
1.3 修改nginx配置檔案
查找nginx的安裝部署
附conf/servers檔案夾下的配置說明
upstream backendServer{
ip_hash;
#此IP和端口是用tomcat或resin啟動後的IP和端口
server :;
}
#這是一個https的server
server{
#設定監聽端口,https通路端口
listen default;
#設定伺服器域名(IP通路和多域名通路可不設定)
#server_name _*;
server_name www.test.com;
#開啟shtml支援
ssi on;
ssi_silent_errors on;
ssi_types text/shtml;
#開啟SSL支援
ssl on;
#下面兩個為導入證書,可根據自己實際情況更改,我的這兩個檔案是放在conf檔案下
ssl_certificate server.pem;
ssl_certificate_key server.key;
ssl_session_timeout m;
ssl_protocols SSLv3 TLSv1;
#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:!SSLv2:+EXP;
#ssl_prefer_server_ciphers on;
#設定主通路日志
#access_log logs/access.log main;
access_log /dev/null;
error_page /html;
error_page /x.html;
#說明location,假設有個一個URL位址為:http://127.0.0.1:8070/plan,經過nginx代理後,https的通路位址為:https://127.0.0.1:443/plan。
#location小括号(userSpace|cloudinvest|servlet|plan|aboutcapital)裡面的值即為URL位址的路徑,表示在userSpace,cloudinvest,setvlet,plan,aboutcapital路徑下都為https的協定。若一個URL位址為:http://127.0.0.1:8070/ques。使用者https協定通路将會報404錯誤。
location ~ (^/(userSpace|cloudinvest|servlet|plan|aboutcapital)/|\.js|\.css|\.png|\.jpg|\.gif){
proxy_pass http://:;
include proxy.conf;
}
#設定監控nginx狀态URL
location /__nginxstatus
{
stub_status on;
access_log off;
}
}
1.4 測試
完成以上步驟後,可以直接測試
例:
http://IP:端口/ques
https://IP:443/plan