# Apache 開啟 HTTPS ###### tags: `Apache`, `Web server`, `HTTPs` PS. *\~夜晚的星空~* 原發表於 HiNet Xuite DATE: 04/24/2012 09:43:05 AM ## 準備 這次用的環境是 CentOS 6.2、Apache/2.2.15 先確認是否有裝上 **mod_ssl** 與 **openssl** 沒有的話就先 `yum install mod_ssl openssl` ## 憑證 * 產出私鑰,並把該私鑰存成檔案: ```shell openssl genrsa -out private.key 2048 ``` - 可以指定長度512/1024/2048 ... - 問到Common Name (eg, YOUR name)時,打入伺服器網址。 * 用剛剛做出來的私鑰,產出憑證請求檔: ```shell openssl req -new -key private.key -out request.csr ``` * 接著交給 CA,請 CA 簽一張憑證。不想花錢請 CA 簽,也可以自己簽,只是 Client 主動驗證憑證時會錯誤。請 CA簽 的話,要注意其編碼格式,apache 讀的是 .PEM-Base64。如果不是該格式,可以用 openssl 進行格式轉換: ```shell openssl x509 -in server.cer -inform DER -out server.crt ``` - **-infrom** 格式是 DER、NET、PEM 其中一種,預設是 PEM - **-outfrom** 格式是 DER、NET、PEM 其中一種,預設是 PEM * 如果是自己簽,也可以用openssl產出憑證: ```shell openssl x509 -req -days 365 -in request.csr -signkey private.key -out server.crt ``` - **-days** 可以指定有效天數 ## Apache 設定 再來是設定 apache config: 確認 conf/httpd.conf 中,有以某種形式將 mod_ssl 和 ssl 的 vhost 設定啟用,一般是會加在 conf.d/ssl.conf 或是 extra 資料夾下有額外有關 ssl 的 config 檔。 * 確認 SSL 的 vhost 中 SSLCertificateFile 指的位置必須是 server.crt 的路徑。 * 確認 SSL 的 vhost 中 SSLCertificateKeyFile 指的位置必須是 private.key 的路徑。 重啟 Apache,測試 https 連線。 ## 參考資料 * OPENSSL入門: http://csc.ocean-pioneer.com/docum/ssl_basic.html * Setting up an SSL secured Webserver with CentOS: http://wiki.centos.org/HowTos/Https * 政府憑證管理中心(GCA) Apache 伺服器SSL 伺服軟體憑證安裝說明: http://gca.nat.gov.tw/download/GCA_Apache_CSR_INSTALL.pdf * 更安全的的連線 Apache + SSL: http://www.l-penguin.idv.tw/article/apache-ssl.htm
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up