iT邦幫忙

DAY 27
9

關於IT資訊界的筆記和學習紀錄系列 第 36

SSL憑證設定(下)

ssl

3.6保護 faq.ca.key

[root@localhost ~]# chmod 0400 /etc/ssl/private/faq.ca.key

Root CA搞定後,即可使用這個Root CA 簽發其它的憑證。

如果沒有要購買SSL憑證的話看第4點(假頁面)
是要購買SSL憑證的話請看第5點
4. 製作伺服器憑證
4.1 接著來製作blog.faq-book.com 的SSL憑證

[root@localhost ~]# openssl genrsa -out /etc/ssl/private/blog.faq-book.com.key 1024 [root@localhost ~]# chmod og-rwx /etc/ssl/private/blog.faq-book.com.key

4.2 填寫憑證申請書,向nuface Root CA 做申請

[root@localhost ~]# openssl req -new -key /etc/ssl/private/blog.faq-book.com.key -out /tmp/ blog.faq-book.com .req

4.3填入資料

Country Name (2 letter code) [TW]:TW                        #請用兩個英文字元表示
State or Province Name (full name) [Taiwan]:Taiwan          #省份名稱
Locality Name (eg, city) [Newbury]:Taipei                   #城市名稱
Organization Name (eg, company) [My Company Ltd]: FAQ-BOOK  # 公司名稱
Organizational Unit Name (eg, section) []:CA                #部門名稱
Common Name (eg, your name or your server's hostname) []:blog.faq-book.com
#網址名稱, 即公用名稱, 您要使用 SSL 加密的站台名稱
Email Address []:derek@faq-book.com                #網站管理者的email address

此外, 尚有一些 extra 的資料, 您可不理會, 直接按 Enter 過去即可, 最後即可產生 blog.faq-book.com.crt 檔

4.4用最高層認證中心(Root CA)簽發憑證

[root@localhost ~]# openssl x509 -req -days 3650 -sha1 \-extfile /etc/ssl/openssl.cnf -extensions v3_req \-CA /etc/ssl/certs/faq.ca.crt -CAkey /etc/ssl/private/faq.ca.key \-CAserial /etc/ssl/faq.ca.srl -CAcreateserial \-in /tmp/bolg.faq-book.com.req -out /etc/ssl/certs/bolg.faq-book.com.crt

4.5刪除憑證申請書

[root@localhost ~]# rm -f /tmp/blog.faq-book.com.req

4.6保護 blog.faq-book.key

[root@localhost ~]# chmod 0400 /etc/ssl/private/blog.faq-book.key
  1. 將第三步所產生的CRT
    5.1存放在/etc/ssl/certs中的faq.ca.crt
    提供給SSL廠商 購買SSL憑證
    5.2在憑證核發後, 您會收到一封 Email, 其中包含憑證檔案(此信會寄到當初申請此faq-book.com的信箱,忘了可用whois查)

5.3請將其剪下, 另存成一個文字檔, 檔名自定, 如 blog.faq-book.com.crt, 並放置於剛剛所建立為了管理方便起見的 certs 資料夾中(當然, 您可以依據自己的需要, 放置於您決定的路徑即可)

5.4最後, 您只須修改 Apache 的設定檔 ssl.conf

[root@localhost ~]# vi /etc/httpd/conf.d/ssl.conf
Listen 443 
#預設值 443 

<VirtualHost _default_:443> 

# General setup for the virtual host 
DocumentRoot "/var/www/html" 
ServerName http://www.ooo.xxx:443 
ServerAdmin mymail@mail.com.tw 
ErrorLog /usr/local/apache/logs/error_log 
TransferLog /usr/local/apache/logs/access_log 
#設定方式與httpd.conf雷同 

# SSL Engine Switch: 
# Enable/Disable SSL for this virtual host. 
SSLEngine on 
#預設值 on 

#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/ssl/certs/winners.ca.crt
#即憑證路徑, 請指向放置憑證檔的路徑 

#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/ssl/private/winners.ca.key
#即私鑰路徑, 請指向放置私鑰檔的路徑 

#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt 
SSLCertificateChainFile /etc/ssl/certs/winners.com.tw.crt
#若您申請購買SSL伺服器數位憑證, 您務必要設定為購買的SSL憑證 

5.5 之後, 您便可重新啟動 apache

[root@localhost ~]# apachectl startssl 
#在啟動過程中, 會要求您輸入密碼如下: 
Enter pass phrase: #請在此輸入您當初產製金鑰對時的密碼
  1. 將 http 與 https 的網頁分開
    剛剛處理的是 Apache 的 SSL ,也就是說原本的 WWW 資料可以分別使用 http 及 https 來瀏覽。
    那可不可以將這兩個傳輸協定分開呢?
    舉例來說,主網頁 (http) 在 /var/www/html 底下,
    但 https 則僅能在 /var/www/www 目錄中。是可以的

    [root@localhost ~]# vi /etc/httpd/conf.d/ssl.conf

    找到底下這兩行,並且將他改掉!

    DocumentRoot "/var/www/www"
    ServerName *:443 #意思是說,任何主機名稱都是到上述的目錄去!
    [root@localhost ~]# apachectl restart

如此一來 https 與 http 是看到不同的地方

SSL憑證設定(上)
全文同步於FAQ-BOOK
IT鐵人文章分享


上一篇
SSL憑證設定(上)
下一篇
LVM系統快照設定教學
系列文
關於IT資訊界的筆記和學習紀錄41
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言