1. 程式人生 > >Nginx http升級到https

Nginx http升級到https

http和https的區別是

有的網站,http開啟的時候,頁面提示不安全,比如你點選下面的網站 【其實是同一個網站】

http://www.511easy.com/bug/login 

http://www.88bugs.com/bug/login

 

怎樣才能去掉這個不安全的提示呢? 從http升級到https唄

最終效果看一下:

 

  

如果目前有一個網站,要怎麼升級為https呢

域名: 511easy.com

有域名了就可以申請免費的ssl證書,如下截圖,基於各個Web伺服器的證書,我這邊用的是Nginx

那然後就需要配置nginx.conf的配置了,大概就是用下面的第三個,前兩個是我用來儲存的。

 https和http相比,更加安全,不盡然,用jmeter/charles/wireshark/fiddle等,生成一個證書,對https的網站都能進行輕易的抓包,大多數的網站和app,我都能夠進行抓包

		upstream tomcatserver1 {
			server 127.0.0.1:8083;
			}
		upstream tomcatserver2 {
			server 127.0.0.1:8085;
			}
			
			
			
	server {
			listen       80;
			server_name  511easy.com;
	 
	 
			location / {
				proxy_pass   http://tomcatserver1;
				index  index.html index.htm;
			}     
		}
	server {
			listen       80;
			server_name  511easy.com;
	  
			location / {
				proxy_pass   http://tomcatserver2;
				index  index.html index.htm;
			}        
		}

  

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

	sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  88bugs;
		location / {
            proxy_pass http://localhost:8083;
        }
     }

	server {
        listen       80;
        server_name  jenkins;
		location / {
            proxy_pass http://localhost:8080;
        }
     }
}

  

 

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

	sendfile        on;

    keepalive_timeout  65;

 
	 server { 
	 listen 443 ssl; 
	 server_name www.511easy.com; 
	 
	 ssl 					on; 
	 ssl_certificate 		1_511easy.com_bundle.crt; 
	 ssl_certificate_key 	        2_511easy.com.key; 
	 ssl_session_timeout 	5m; 
		 
	 location / {
            proxy_pass http://localhost:8083;
        }
 
	 }
}

 

鞏固一下這幾個縮寫名詞的含義

 

HTTP --- Hyper Text Transfer Protocol,超文字傳輸協議,是一種建立在TCP上的無狀態連線,整個基本的工作流程是客戶端傳送一個HTTP請求
HTTPS ---- Hyper Text Transfer Protocol over Secure Socket Layer 或 Hypertext Transfer Protocol Secure
全稱是:超文字安全傳輸協議,可以簡單理解為使用SSL加密傳輸的HTTP協議

 


HTTP的預設埠是80,HTTPS的預設埠是443
SSL是為網路通訊提供安全及資料完整性的一種安全協議。

 

為什麼要使用HTTPS
為了保護資訊傳輸的安全性,資料完整性。讓訪客覺得網站可信任,對於國內的網路環境,也可以防止寬頻運營商強制給網站掛廣告。

 

 如果希望一臺伺服器上,兩個埠,分別用不用的域名執行不同的埠,Nginx可以這麼配置

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

	sendfile        on;

    keepalive_timeout  65;

 
	 server { 
	 listen 443 ssl; 
	 server_name www.88bugs.com; 
	 
	 ssl_certificate 		1_88bugs.com_bundle.crt; 
	 ssl_certificate_key 	2_88bugs.com.key; 
	 ssl_session_timeout 	5m; 
		 
	 location / {
            proxy_pass http://localhost:8083;
        } 
	 }
	 
	 server { 
	 listen 443 ssl; 
	 server_name www.511easy.com; 
	 
	 ssl_certificate 		1_511easy.com_bundle.crt; 
	 ssl_certificate_key 	2_511easy.com.key; 
	 ssl_session_timeout 	5m; 
		 
	 location / {
            proxy_pass http://localhost:8085;
        } 
	 }
	 
	 
	 
}

  

https://www.88bugs.com/bug/login

https://www.511easy.com/   【目前修改後是指向另一個埠的專案了】