OK論壇

 找回密碼
 註冊
查看: 1274|回復: 0

Windows下安裝Apache + SSL

 關閉 [複製鏈接]
  • TA的每日心情
    奮斗
    2012-7-26 08:00 PM
  • 簽到天數: 16 天

    連續簽到: 1 天

    [LV.4]偶爾看看III

    發表於 2009-7-13 08:14:11 | 顯示全部樓層 |閱讀模式
    本帖最後由 ‵Super”貓 於 2009-7-13 09:12 AM 編輯

    前陣子剛好需要使用自發伺服器認證,由於使用的是Windows IIS,因此很簡單的幾個步驟就啟用。最近剛好有人詢問Windows下如何使用Apache Server加上OpenSSL?因此找了一些資料實地安裝了一遍,資料來源是:
    http://blog.ericsk.org/archives/215
    http://www.pczone.com.tw/vbb3/thread/47/96241/

    這兩個網站基本上說明的已經算很清楚,但對於Apache不熟悉的人,可能還有一些問題,因此把資料匯整一下。

    (1)首先下載Apache的OpenSSL版本:
    http://209.61.202.80/apache/Apache_2.2.3-Openssl_0.9.8d-Win32.zip
    假設你把它安裝在D:\Apache2.2\目錄下
    安裝時會詢問你domain name、server name與admin email
    你輸入的內容會寫到httpd.conf檔案內 (d:\apache2.2\conf\httpd.conf)

    httpd.conf是啟動Apache的主要設定檔案

    (2)打開httpd.conf
    將LoadModule ssl_module modules/mod_ssl.so前面的#去掉
    將Include conf/extra/httpd-ssl.conf前面的#去掉
    將httpd.conf存檔


    (3)打開D:\apache2.2\conf\extra\httpd-ssl.conf
    將#SSLMutex  "file: D:/Apache2.2/logs/ssl_mutex"
    改成SSLMutex none

    並確認:
    <VirtualHost _default_:443>
    #   General setup for the virtual host
    DocumentRoot "D:/Apache2.2/htdocs"
    ServerName your.server.com.tw:443
    ServerAdmin
    [email protected]
    ErrorLog "D:/Apache2.2/logs/error_log"
    TransferLog "D:/Apache2.2/logs/access_log"

    以上your.server.com是你的機器名稱,如果沒有domain name,可以用ip來代替
    這個檔案主要是Apache開啟後,需要知道SSL的設定組態

    (4)繼續看httpd.conf
    SSLCertificateFile "D:/Apache2.2/conf/ssl/server.crt"
    SSLCertificateKeyFile "D:/Apache2.2/conf/ssl/server.key"
    如果不需要瀏覽端認證,以下可以不管他:
    #SSLVerifyClient require
    #SSLVerifyDepth  10

    如果自發認證,以下可以不管他:
    #SSLCertificateChainFile "D:/Apache2.2/conf/server-ca.crt"
    #SSLCACertificatePath "D:/Apache2.2/conf/ssl.crt"
    #SSLCACertificateFile "D:/Apache2.2/conf/ssl.crt/ca-bundle.crt"
    #SSLCARevocationPath "D:/Apache2.2/conf/ssl.crl"
    #SSLCARevocationFile "D:/Apache2.2/conf/ssl.crl/ca-bundle.crl"

    修改完後將httpd.conf存檔

    (5)要產生SSL所需要的key的前置動作
    這個動作牽涉到幾個:
    (a)Apache目錄下的/bin/openssl.exe
    (b)Apache目錄下的/bin/openssl.cnf (不是openssl.conf喔)

    打開openssl.cnf,看看內容:
    [ CA_default ]
    dir= ./ssl   

    你先在Apache目錄下的/bin/下建立ssl目錄
    也就是有了 d:\apache2.2\bin\ssl,這個目錄放置SSL檔案


    (6)在 d:\apache2.2\bin\ssl下建立一個空檔案
    index.txt


    (7)在 d:\apache2.2\bin\ssl下建立一個檔案serial,內容就輸入01
    (不要副檔名喔)

    所以目前d:\apache2.2\bin\ssl有兩個檔案: index.txt與serial
    在d:\apache2.2\bin\ssl下再新建一個目錄newcerts

    (8)產生SSL key
    以dos command進到d:\apache2.2\bin
    並以下面指令產生key(中間過程會要你輸入一些組態...自己看看...應該沒問題)

    d:\apache2.2\bin
    openssl genrsa -des3 -out ssl/ca.key 1024

    d:\apache2.2\bin
    openssl req -config openssl.cnf -new -key ssl/ca.key -out ssl/ca.csr

    d:\apache2.2\bin
    openssl x509 -days 3650 -req -signkey ssl/ca.key -in ssl/ca.csr -out ssl/ca.crt

    d:\apache2.2\bin
    openSSL genrsa -out ssl/server.key 1024

    d:\apache2.2\bin
    openssl req -config openssl.cnf -new -key ssl/server.key -out ssl/server.csr

    d:\apache2.2\bin
    openssl ca -config openssl.cnf -days 3650 -cert ssl/ca.crt -keyfile ssl/ca.key -in ssl/server.csr -out ssl/server.crt

    檢查你的d:\apache2.2\bin\ssl下
    是否有了11個檔案及一個目錄 ,將整個ssl目錄copy到d:\apache2.2\conf下


    (9)現在重新開啟Apache,應該已經可以用https://來開你的SSL
    如果不能的話,看看d:\apache2.2\logs\error.log是哪裡出問題

    評分

    參與人數 1積分 +15 現金 +15 積極性 +15 收起 理由
    ‵Super”貓 + 15 + 15 + 15 活動加分 結束日期2009/7/31

    查看全部評分

    回復

    使用道具 舉報

    您需要登錄後才可以回帖 登錄 | 註冊

    本版積分規則

    Archiver|手機版|小黑屋|OK討論區

    GMT+8, 2025-6-24 06:50 AM , Processed in 0.050395 second(s), 21 queries , Gzip On.

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回復 返回頂部 返回列表