Nginx實戰案例—HTTPS加密認證
同http服務一樣,nginx也可以設置https加密認證。當我們訪問http://www.westos.org時,它會幫我們自動跳轉到https://www.westos.org
下面是設定加密認證的步驟:
step1 修改配置文件:
vim /usr/local/nginx/conf/nginx.conf
103 server {
104 listen 443 ssl;
105 server_name www.westos.org;
106
107 ssl_certificate cert.pem;
108 ssl_certificate_key cert.pem;
109
110 ssl_session_cache shared:SSL:1m;
111 ssl_session_timeout 5m;
112
113 ssl_ciphers HIGH:!aNULL:!MD5;
114 ssl_prefer_server_ciphers on;
115
116 location / {
117 root /web;
118 index index.html index.htm;
119 }
120 }
step2 製作key:
cd /etc/pki/tls/certs/
make cert.pem
step3 發送key:
cp cert.pem /usr/local/nginx/conf/
step4 製作發佈頁面:
mkdir /web
vim /web/index.html
step5 重新啓動nginx:
nginx -t #語法檢測
nginx -s reload #在不暫停服務的情況下重新加載
step6 測試:
https://www.westos.org/ 添加證書