首頁  >  文章  >  運維  >  Nginx怎麼把http升級到https

Nginx怎麼把http升級到https

WBOY
WBOY轉載
2023-05-28 22:52:571100瀏覽

http和https的差別是

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

Nginx怎麼把http升級到https

Nginx怎麼把http升級到https 

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

最終效果看一下:

Nginx怎麼把http升級到https 

Nginx怎麼把http升級到https

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

網域: 511easy.com

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

Nginx怎麼把http升級到https

那接著就需要設定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;
  }
  } 
}

以上是Nginx怎麼把http升級到https的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除