安裝證書
文件說明:
1. 證書文件214525340260509.pem,包含兩段內容,請不要刪除任何一段內容。
2. 如果是證書系統創建的CSR,還包含:證書私鑰文件214525340260509.key。
( 1 ) 在Nginx的安裝目錄下創建cert目錄,並且將下載的全部文件拷貝到cert目錄中。如果申請證書時是自己創建的CSR文件,請將對應的私鑰文件放到cert目錄下並且命名為214525340260509.key;
( 2 ) 打開 Nginx 安裝目錄下 conf 目錄中的 nginx.conf 文件,找到:
# HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # # #} #}
( 3 ) 將其修改為 (以下屬性中ssl開頭的屬性與證書配置有直接關系,其它屬性請結合自己的實際情況復制或調整) :
server { listen 443; server_name Domain; ssl on; root html; index index.html index.htm; ssl_certificate cert/214525340260509.pem; ssl_certificate_key cert/214525340260509.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } }
保存退出。
( 4 )重啟 Nginx。
( 5 ) 通過 https 方式訪問您的站點,測試站點證書的安裝配置。如遇到證書不信任問題,請查看幫助視頻。
NGINX 配置使用 301 重定向,把網站的 HTTP 重定向到 HTTPS 。:
server {
listen 80; server_name Domain; return 301 https://$host$request_uri; }
上面的配置會讓對 HTTP 網頁的請求,重定向到 HTTPS 版本的網頁上。
還可以mod_rewrite模塊做重定向實
證書安裝完成后,只有在地址欄輸入https://網址才能進入https協議模式,默認仍然為http模式,可通過NGINX找到你mod_rewrite模塊做重定向實現輸入網址后自動跳轉為https協議模式
進入Apache配置頁面,修改httpd.conf文件,查找到 #LoadModule rewrite_module modules/mod_rewrite.so 並將前面的#號去掉,如果找不到該語句自行添加,進入httpd根目錄下查看文件夾modules內是否存在文件mod_rewrite.so,若沒有可自行下載並上傳。
在httpd.conf文件中,添加代碼:
- RewriteEngine on
- RewriteCond %{SERVER_PORT} !^443$
- RewriteRule ^(.*)?$ https://%{SERVER_NAME}$1 [L,R]