在 windows 環境底下設定 apache ( 32 位元 ) SSL 憑證讓網址變成 https

此環境為 apache、mysql、php 獨立安裝的 windows 環境
1.首先切換到Apache的bin目錄
 這裡的apache的目錄在C:\FMS\apache\bin

2.使用OpenSSL建立『server.key』私鑰檔案,並輸入自訂短密碼
openssl genrsa -out server.key 2048
 
這邊請不要加上 -des or -des3 來使用密碼保護
因為有密碼保護的 key,會讓 apache 在啟動時詢問密碼,這樣 linux 會停住
而 windows 則因為不支援密碼輸入,所以 apache 會開不起來

3.使用私鑰去建立『server.csr』憑證請求檔
openssl req -new -key server.key -out server.csr -config ..\conf\openssl.cnf

4.在建立憑證請求檔時會詢問相關資訊
Country Name (2 letter code) [AU]:所在國家簡寫TW
State or Province Name (full name) [Some-State]:所在國家Taiwan
Locality Name (eg, city) []:所在城市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:公司名稱
Organizational Unit Name (eg, section) []:組織名稱
Common Name (e.g. server FQDN or YOUR name) []:網址名稱
Email Address []:聯絡人信箱

5.使用憑證請求檔及私鑰檔去建立3650天的X.509格式憑證的CRT憑證檔
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

6.以上步驟完成後會得到共三個檔案『server.key』、『server.csr』、『server.crt』請將三個檔案移到『\conf』目錄下。

7.打開『httpd.conf』檔案找到以下句並取消註解
LoadModule ssl_module modules/mod_ssl.so

8.因為預設建立的憑證在 windows 32 位元底下會發生錯誤(若安裝的apache 為 64 位元版則不用理會這段命令),所以需要輸入下列指令並重新將 server.key 複製到 http\conf 資料夾底下
ren server.key server.key.org
openssl rsa -in server.key.org -out server.key

9.在 httpd.conf 文件中新增下列設定
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName 網址
    DocumentRoot "C:/你的web/www"
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
    ServerName 網址
    DocumentRoot "C:/你的web/www"
    SSLEngine on
    SSLCertificateFile "C:\你的web\apache\conf\server.crt"
    SSLCertificateKeyFile "C:\你的web\apache\conf\server.key"  
    SSLCertificateChainFile "C:\你的web\apache\conf\server.crt"
</VirtualHost>

10.利用 httpd 檢測語法指令檢查設定參數
httpd -t

11.關閉 windows 防火牆,開啟瀏覽器 https://{網址名稱}

留言

這個網誌中的熱門文章

c語言-關於#define用法

CMD常用網管指令

PHP 與 JavaScript 之間傳值利用 json