標籤:輸入密碼 壓縮包 .com 利用 article step version sign 參數
1、下載 mod_ssl 和 apache
登入http://www.modssl.org/source/,下載
mod_ssl-2.8.31-1.3.41.targz;
2.8.31是mod_ssl版本號碼;1.3.41是apache版本號碼(mod_ssl和apache是一一對應的)
apache_1.3.41.tar.gz (https://archive.apache.org/dist/httpd/)
2、下載openssl
openssl-0.9.6.tar.gz (http://www.openssl.org/source/openssl-0.9.6.tar.gz)
[注意:
將下載好的壓縮包統一放在/usr/local/src/下(便於管理接下來的配置)]
解壓
tar zxvf *.tar.gz
安裝
一、配置apache
# cd /usr/local/src/apache_1.3.41
# ./configure --prefix=/usr/local/apache
二、編譯openssl
# cd ../openssl-0.9.6
# ./config --prefix=/usr/local/openssl
[注意:這裡是 config 而不是 configure。]
# make
# make test
# make install
make[1]: gcc: Command not found, download gcc http://ftp.gnu.org/gnu.
三、配置mod_ssl
# cd ../mod_ssl-2.8.31-1.3.41
# ./configure --with-apache=../apache_1.3.41
四、編譯apache
# cd ../apache_1.3.41
# SSL_BASE=../openssl-0.9.6
#./configure --prefix=/usr/local/apache --enable-module=ssl --enable-shared=ssl
# make
五、產生CA
# make certificate TYPE=custom
這一步要產生你自己的 CA (如果你不知道,我也不能細說了,簡單地 說就是認證中心),和用它來為你的伺服器簽署認證。 有很多東西要輸入。
______________________________________________________________________
STEP 0: R選擇演算法,使用預設的 RSA
______________________________________________________________________
STEP 1: 產生 ca.key,CA的私人密鑰
______________________________________________________________________
STEP 2: Generating X.509 certificate signing request for CA [ca.csr]
You are about to be asked to enter information that will be incorporated
into your certificate request.
(為CA產生X.509的認證請求 ca.csr 要輸入一些資訊)
Country Name: cn 國家代碼,兩個字母
State or Provice name: fujain省份
Locality Name: xiamen城市名
Organization Name: home CA 組織名,隨便寫吧
Organization Unit Name: home CA
Common Name: home CA
Email Address: [email protected]我的Email
Certificate Validity: 4096 四千多天,夠了吧
______________________________________________________________________
STEP 3: Generating X.509 certificate for CA signed by itself [ca.crt]
Certificate Version (1 or 3) [3]:1
______________________________________________________________________
STEP 4: Generating RSA private key for SERVER (1024 bit) [server.key]
(產生伺服器的私人密鑰,server.key)
______________________________________________________________________
STEP 5: Generating X.509 certificate signing request for SERVER [server.csr]
You are about to be asked to enter information that will be incorporated
into your certificate request.
(產生伺服器的認證請求,server.csr 要輸入一些資訊,和STEP 2類似)
[注意:
Common Name是你的網站網域名稱,如 www.mydomain.com
Certificate Validity不要太大,365就可以了]
Country Name: cn
State or Provice name: fujain
Locality Name: xiamen
Organization Name: home
Organization Unit Name: home
Common Name: home
Email Address: [email protected]
Certificate Validity: 365
______________________________________________________________________
STEP 6: Generating X.509 certificate signed by own CA [server.crt]
Certificate Version (1 or 3) [3]:1
(為你的伺服器簽名,得到server.crt)
______________________________________________________________________
STEP 7: Enrypting RSA private key of CA with a pass phrase for security [ca.key]
(為你的 ca.key加密)
Encrypt the private key now? [Y/n]: y
______________________________________________________________________
STEP 8: Enrypting RSA private key of SERVER with a pass phrase for security [server.key]
(為你的 server.key加密)
Encrypt the private key now? [Y/n]: y
六、apache安裝
# make install
七、配置http.conf
# vi /usr/local/apache/conf/httpd.conf
修改BindAddress 和 ServerName 加入關於PHP4的行 .如果要改變 DocumentRoot 要記得把httpd.conf裡SSL Virtual Host Context部分的DocumentRoot設定也改掉。
SSLCertificateFile和SSLCertificatKeyFile的設定也在 SSL Virtual Host Context部分。 它可能是這樣設定的:
SSLCertificateFile /usr/local/apache/conf/ssl.crt/server.crt
SSLCertificateKeyFile /usr/local/apache/conf/ssl.key/server.key
要注意ssl.key ssl.crt等目錄和檔案的許可權! 所有的key,csr,crt,prm檔案都應該設為 400 屬性!
八、啟動https連接埠
# cd /usr/local/apache
# bin/apachectl startssl
輸入密碼:ccy123
[錯誤:
#cd /usr/local/apache/bin
#apachectl startssl]
九、測試
#netstat -tunal |grep 443
linux上瀏覽器 / window 36瀏覽器輸入:https://localhost/
[注意:
在window上的IE瀏覽器輸入會報錯]
雖然在安裝MOD_SSL時已經使用 make certificate 命令建立了伺服器 的認證簽名,但是有時你可能需要改變它。
當然有很多自動的指令碼可以實現它,但是最可靠的方法是手工簽署 認證。
十、維護
1)/usr/local/openssl/bin加入 執行檔案尋找路徑。
2)將MOD_SSL的原始碼分類樹下的pkg.contrib目錄中,檔案名稱為 sign.sh拷貝到 /usr/local/openssl/bin 中
十一、建立CA
1)先建立一個 CA 的認證,首先為 CA 建立一個 RSA 私用密鑰
#cd /usr/local/openssl/bin
#openssl genrsa -des3 -out ca.key 1024
#chmod 400 ca.key(產生 ca.key 檔案屬性改為400,並放在安全的地方)
#openssl rsa -noout -text -in ca.key(查看ca.key內容)
2)利用 CA 的 RSA 密鑰建立一個自簽署的 CA 認證(X.509結構)
#openssl req -new -x509 -days 3650 -key ca.key -out ca.crt
然後需要輸入下列資訊:
Country Name: cn
State or Province Name: fujain
Locality Name: xiamen
Organization Name: Family home
Organizational Unit Name: home
Common Name: home
Email Address: [email protected]
#chmod 400 ca.crt
#openssl x509 -noout -text -in ca.crt
十二、建立伺服器憑證簽署請求
1)首先為你的 Apache 建立一個 RSA 私用密鑰:
#openssl genrsa -des3 -out server.key 1024
#chmod 400 server.key
#openssl rsa -noout -text -in server.key
2)用server.key 產生認證簽署請求 CSR.
#openssl req -new -key server.key -out server.csr
#openssl req -noout -text -in server.csr
3)下面可以簽署認證了,需要用到指令碼 sign.sh
#./sign.sh server.csr(可以得到server.crt)
#chmod 400 server.crt
#rm server.csr
十三、最後apache設定
如果你的apache編譯參數prefix為/usr/local/apache,
拷貝server.crt 和 server.key 到 /usr/local/apache/conf .
修改httpd.conf 將下面的參數改為:
SSLCertificateFILE /usr/local/apache/conf/server.crt
SSLCertificateKeyFile /usr/local/apache/conf/server.key
十四、開啟
#apachectl startssl
[注意:
配置修改後,必須重啟apache才生效]
Linux_install mod_ssl openssl apache