#創建服務器密鑰 openssl genrsa -des3 1024 > /usr/local/apache/conf/server.key # 從密鑰中刪除密碼(以免系統啓動後被詢問口令) openssl rsa -in /usr/local/apache/conf/server.key > /usr/local/apache/conf/server2.key mv /usr/local/apache/conf/server2.key /usr/local/apache/conf/server.key #創建服務器密鑰請求文件 openssl req -new -key /usr/local/apache/conf/server.key -out /usr/local/apache/conf/server.csr 5>openssl x509 -in /usr/local/apache/conf/server.csr -out # 創建服務器證書 /usr/local/apache/conf/server.crt -req -signkey /usr/local/apache/conf/server.key -days 365
打開ssl模塊,沒有這個模塊就須要安裝依賴包:mod_ssl,安裝後就會在modules裏面找到:web
LoadModule ssl_module modules/mod_ssl.so
引入ssl配置文件,增長支持ssl:apache
Include conf/extra/httpd-ssl.conf(去掉行首的註釋)
RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]
LoadModule ssl_module modules/mod_ssl.so Listen 443 SSLPassPhraseDialog builtin SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000) SSLSessionCacheTimeout 300 SSLMutex default SSLRandomSeed startup file:/dev/urandom 256 SSLRandomSeed connect builtin SSLCryptoDevice builtin SSLProtocol all -SSLv2 -SSLv3 SSLHonorCipherOrder on SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4: <VirtualHost _default_:443> # 必須有一個虛擬主機,這樣纔可使用跳轉功能和使用443端口訪問 DocumentRoot "/home/store/webroot" Servername https://xxx.com/ ErrorLog logs/ssl_error_log TransferLog logs/ssl_access_log LogLevel warn SSLEngine on SSLCertificateFile /etc/httpd/conf/cert/xxx.com.crt SSLCertificateKeyFile /etc/httpd/conf/cert/xxx.com.key </VirtualHost>
service httpd restart瀏覽器
Invalid command 'SSLPassPhraseDialog', perhaps misspelled or defined by a module not included in the server configuration
到apache的bin 目錄下面執行 ./httpd -l 看看有沒有mode_ssl.c,這個錯誤說明ssl模塊安裝沒有成功。
解決辦法:服務器
一、從新編譯apache,加上--enable-ssl --with-ssl參數dom
二、把ssl模塊加入到已經編譯好的apache中
首先,使用 whereis openssl 命令獲取lib和include的路徑ui
[root@robot /usr/local/apache/modules]# whereis openssl openssl: /usr/bin/openssl /usr/lib/openssl /usr/include/openssl /usr/share/man/man1/openssl.1ssl.gz
而後 在apache 源碼的modules/ssl文件夾下,使用命令/usr/sbin/apxs -i -a -D HAVE_OPENSSL=1 -I/usr/include/openssl/ -L/usr/lib/openssl/ -c *.c -lcrypto -lssl -ldl
(apxs須要安裝http-devel纔有,雖然如此,我仍是沒有編譯成功,因而就在其餘已經編譯了這個模塊的機器上拷貝mod_ssl.so到apache模塊目錄/usr/local/apache/modules)加密