為什么使用https協(xié)議泊脐?
使用http協(xié)議大都面臨以下問題:
- 網(wǎng)站頁面會被篡改,非法跳轉(zhuǎn)
- 網(wǎng)站被植入廣告
https協(xié)議是由SSL+HTTP協(xié)議構(gòu)建的可進行加密傳輸课蔬、身份認證的網(wǎng)絡(luò)協(xié)議囱稽,要比http協(xié)議安全,可防止數(shù)據(jù)在傳輸過程中不被竊取二跋、改變战惊,確保數(shù)據(jù)的完整性。
HTTPS是現(xiàn)行架構(gòu)下最安全的解決方案扎即,雖然不是絕對安全吞获,但它大幅增加了中間人攻擊的成本。
Nginx配置
- http
# 將http的所有請求進行重定向到https
server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 permanent;
}
- https
# 基本上使用nginx默認的配置
server {
listen 443 ssl;
server_name localhost;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 將nginx的請求重定向到本地服務(wù)
location /index {
proxy_pass http://127.0.0.1:9999;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
}
需要注意的問題
- 云服務(wù)器控制臺需要配置對應(yīng)的
80
與443
端口 - https的配置文件中需要修改自己申請的
CA證書
文件路徑 - 修改配置后需要重啟nginx