1、打開cmd ,輸入 F: // 切換到Apache安裝路徑,我的Apache安裝目錄在 F盤 2、cd F:\Apache\bin 3、set "openssl_conf = F:\Apache\conf\openssl.cnf" 臨時設置openssl_conf路徑,也可在環境變數中建新項目, ...
1、打開cmd ,輸入 F: // 切換到Apache安裝路徑,我的Apache安裝目錄在 F盤
2、cd F:\Apache\bin
3、set "openssl_conf = F:\Apache\conf\openssl.cnf"
臨時設置openssl_conf路徑,也可在環境變數中建新項目,鍵為 OPENSSL_CONF,值為 F:\Apache\conf\openssl.cnf (看自己的安裝路徑),不然在生成key時會報“WARNING: can't open config file: c:/openssl-1.0.2j-win64/ssl/openssl.cnf”錯誤。
4、openssl genrsa -out server.key 1024 // 生成私密key
5、copy server.key server.key.org // 複製server.key 防止啟動Apache要密碼
6、openssl rsa -in server.key.org -out server.key
7、openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt // 生成證書,會要求填寫國家、省份、城市、功能變數名稱、郵箱等信息
8、配置Apahce !!! 核心步驟 !!!
8.1 在http.conf文件中去掉下麵代碼前的#號
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so #LoadModule ssl_module modules/mod_ssl.so #Include conf/extra/httpd-ssl.conf
8.2 修改 F:/Apache/conf/extra/httpd-ssl.conf 文件
<VirtualHost _default_:443> DocumentRoot "F:/Apache/htdocs/ushark.net" ServerName www.ushark.net:443 SSLCertificateFile "F:/Apache/bin/server.crt" SSLCertificateKeyFile "F:/Apache/bin/server.key" </VirtualHost>
9、配置http自動跳轉到https,在 httpd-vhosts.conf 文件中編輯如下內容,也可參考這篇文章:https://wiki.apache.org/httpd/RedirectSSL
<VirtualHost *:80>
DocumentRoot "F:/Apache/htdocs/ushark.net"
ServerName www.ushark.net
Redirect / https://www.ushark.net/ # !!! 核心代碼 !!!
</VirtualHost>
10、httpd -k restart // 重新啟動Apache,報錯的話就查找相應原因解決