Apache搭建HTTPS Virtual Host
Apache 搭建HTTPS Virtual Host
1.創(chuàng)建SSL證書
首先需要安裝openssl,linux系統默認已安裝,如沒有則用以下命令安裝:
sudo apt-get install openssl
sudo apt-get install libssl-dev
創(chuàng)建證書:
cd /etc/ssl/private
sudo openssl req -new -x509 -days 365 -sha1 -newkey rsa:1024 -nodes -keyout demo.key -out demo.crt
參數說明:
-x509 顯示證書和簽名工具
-days 證書的有效期
-sha1 證書加密算法
-newkey rsa:1024 創(chuàng)建一個新key,1024表示公鑰長度為1024bits
命令執(zhí)行完會創(chuàng)建demo.key與demo.crt
更多參數說明可以參考:http://www.openssl.org/docs/apps/openssl.html
創(chuàng)建步驟:
root@ubuntu:/etc/ssl/private# sudo openssl req -new -x509 -days 365 -sha1 -newkey rsa:1024 -nodes -keyout demo.key -out demo.crt Generating a 1024 bit RSA private key .......++++++ ...........++++++ writing new private key to 'demo.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:GD Locality Name (eg, city) []:GZ Organization Name (eg, company) [Internet Widgits Pty Ltd]:fdipzone.Ltd Organizational Unit Name (eg, section) []:test Common Name (eg, YOUR name) []:demo.fdipzone.com Email Address []:fdipzone@gmail.com root@ubuntu:/etc/ssl/private# |
需要填寫的項目:
Country Name (2 letter code) [AU]: 國家 State or Province Name (full name) [Some-State]:省份 Locality Name (eg, city) []:城市 Organization Name (eg, company) [Internet Widgits Pty Ltd]:公司名稱 Organizational Unit Name (eg, section) []: 組織單位名稱 Common Name (eg, YOUR name) []: 填寫域名 Email Address []:電郵地址 |
2.創(chuàng)建Virtual Host
<VirtualHost *:443> DocumentRoot /home/fdipzone/demo ServerName demo.fdipzone.com <Directory "/home/fdipzone/demo"> allow from all AllowOverride all Options -Indexes FollowSymLinks </Directory> SSLEngine on SSLCertificateFile /etc/ssl/private/demo.crt SSLCertificateKeyFile /etc/ssl/private/demo.key SSLCipherSuite AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5 SSLHonorCipherOrder on </VirtualHost> |
開啟SSL Engine及設置使用的證書,端口443
SSLEngine on
SSLCertificateFile /etc/ssl/private/demo.crt
SSLCertificateKeyFile /etc/ssl/private/demo.key