在Apache配置https方式訪問網站

  1. 引入httpd-ssl.conf文件

    在相應的目錄下找到httd-conf文件  通常都是在/etc/apache2/httpd.conf  下 apache

    取消掉Include /private/etc/apache2/extra/httpd-ssl.conf 前面的註釋符號#  也就是引入httpd-ssl.conf文件windows

  2. 生成KEY和證書。[mac下]     【windows xamp 下不須要】

    由於在 /private/etc/apache2/extra/httpd-ssl.conf 已經配置好KEY 和證書的名字因此下面的步驟中請不要修改生成的KEY文件的名字 若是修改請把httpd-ssl.conf中相應的文件路徑和名字也修改測試

    cd /etc/apache2spa

    (1) sudo openssl genrsa -des3 -out server.key 1024rest

    enter a passphrase for your private key. (輸入key 的密碼在接下來的過程當中會用到,隨意輸入123456)    ;code

    (2) openssl req -new -key server.key -out server.csrserver

    接下來的省城市email等等選項能夠留空 即按enter 鍵進入下一步 ssl

    (3) sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crtopenssl

    (4)備份class

    cp server.key server.key.copy    

    openssl rsa -in server.key.copy -out server.key

  3. 重啓Apache  

    sudo  apachectl restart

    反問 https:localhost便能進入相應頁面

配置站點
(1)在httpd-ssl.conf文件頭部添加  NameVirtualHost *:443
(2)在文件底部添加相似下面配置 便可
<VirtualHost *:443>
    DocumentRoot "path_to_your_projects"
    ServerName localhost.xxx
    ErrorLog "/your_log_path/apache2/xxx-error_log"
    TransferLog "/your_log_path/apache2/xxx-access_log"
    SSLEngine on
   【mac環境下使用這個】
    SSLCertificateFile "/private/etc/apache2/server.crt" 
    SSLCertificateKeyFile "/private/etc/apache2/server.key" 
   【win環境下使用這個】
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
</VirtualHost>
注意:通常來講 SSLCertificateFile 和SSLCertificateKeyFile的地址在httpd-sll.conf 都有默認地址。咱們儘可能不去修改他

  大功告成!! 

以上步驟 mac下 是所有要執行

windows【博主是在xamp環境測試的    其餘環境的 自行測試】下 不須要第二步 其餘的須要

相關文章
相關標籤/搜索