全站HTTPS簡單實踐,全站https
第一個裡程碑:建立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 incorporated10 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 blank13 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]# ls2 server.crt server.key3 4 產生的密鑰檔案5 [root@web01 backup]# ll6 total 87 -rw-r--r-- 1 root root 1375 Nov 6 14:07 server.crt8 -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.etiantian.org; 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.etiantian.org
2)選擇進階,繼續前往www.etiantian.org(不安全) 由於ssl認證是自己生產的,會有這樣的一個問題。
3)網站訪問正常。
這種小綠鎖的ssl,需要購買ssl認證。