第一個里程碑:創建https證書
1 [root@web01 backup]# openssl req -new -x509 -nodes -out server.crt -keyout server.key 2 3 Generating a 2048 bit RSA private key 4 ......................................................+++ 5 ...................................+++ 6 7 writing new private key to 'server.key' 8 ----- 9 You are about to be asked to enter information that will be incorporated 10 into your certificate request. 11 What you are about to enter is what is called a Distinguished Name or a DN. 12 There are quite a few fields but you can leave some blank 13 For some fields there will be a default value, 14 If you enter '.', the field will be left blank. 15 ----- 16 Country Name (2 letter code) [XX]:CH #國家名稱 17 State or Province Name (full name) []:bj #省 18 Locality Name (eg, city) [Default City]:bj #市 19 Organization Name (eg, company) [Default Company Ltd]:ZNIX #組織名稱 20 Organizational Unit Name (eg, section) []:ZNIX #組織名稱 21 Common Name (eg, your name or your server's hostname) []:ZNIX #服務器名稱 22 Email Address []:ADMIN@ZNIX.TOP #郵箱
查看產生的證書
1 [root@web01 backup]# ls 2 server.crt server.key 3 4 生成的密鑰文件 5 [root@web01 backup]# ll 6 total 8 7 -rw-r--r-- 1 root root 1375 Nov 6 14:07 server.crt 8 -rw-r--r-- 1 root root 1704 Nov 6 14:07 server.key
openssl參數說明
參數 |
參數說明 |
req |
PKCS#10 X.509 Certificate Signing Request (CSR)Management. PKCS#10 X.509證書簽名請求(CSR)管理。 |
x509 |
X.509 Certificate Data Management. X.509證書數據管理。 |
第二個里程碑:修改nginx配置文件
1 [root@web01 ~]# cat /application/nginx/conf/extra/www.conf 2 server { 3 listen 443 ssl; 4 server_name www.nmtui.com; 5 ssl_certificate /application/nginx/key/server.crt; 6 ssl_certificate_key /application/nginx/key/server.key; 7 ssl_session_cache shared:SSL:1m; 8 ssl_session_timeout 5m; 9 ssl_ciphers HIGH:!aNULL:!MD5; 10 ssl_prefer_server_ciphers on; 11 12 location / { 13 root html/www; 14 index index.php ; 15 } 16 location ~* .*\.(php|php5)?$ { 17 root html/www; 18 fastcgi_pass 127.0.0.1:9000; 19 fastcgi_index index.php; 20 include fastcgi.conf; 21 } 22 access_log logs/access_www.log main; 23 }
模塊參數說明
模塊名稱 |
說明 |
ssl_prefer_server_ciphers |
指定在使用SSLv3和TLS協議時,服務器密碼應優先於客戶端密碼。 |
ssl_ciphers |
指定啟用的密碼。密碼以OpenSSL庫理解的格式指定 |
ssl_session_timeout |
指定客戶端可以重新使用會話參數的時間。 |
ssl_session_cache |
設置存儲會話參數的高速緩存的類型和大小。 |
ssl_certificate |
指定file具有給定虛擬服務器的PEM格式的證書。如果除了主要證書之外還應該指定中間證書,則應該按照以下順序在同一個文件中指定它們:主要證書首先是中間證書,然后是中間證書。PEM格式的密鑰可以放在同一個文件中。 |
ssl_certificate_key |
指定file給定虛擬服務器的PEM格式的秘密密鑰。 |
1.1.2 客戶端訪問
1)瀏覽器訪問https://www.nmtui.com
2)選擇高級,繼續前往www.nmtui.com(不安全) 由於ssl證書是自己生產的,會有這樣的一個問題。
3)網站訪問正常。
這種小綠鎖的ssl,需要購買ssl證書。