windows下面配置apache+https


在Apache里配一個<VirtualHost *:6044>,然后針對這個6044設置https,https可反向代理映射到http地址,但http不可反向代理映射到https地址。

需要修改httpd.conf 、httpd-vhosts.conf兩個文件

1、修改conf/httpd.conf 取消以下注釋,使appache啟動時調用ssl服務:

#LoadModule ssl_module modules/mod_ssl.so (去掉前面的‘#’號)
#Include conf/extra/httpd-ssl.conf        (去掉前面的‘#’號)

2、生成證書

win+R:cmd進入命令行,進入apache安裝目錄的bin文件 cd C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin

設置OPENSSL_CONFIG配置,執行命令 set OPENSSL_CONF=..\conf\openssl.cnf

(a)生成服務端的key文件

  執行命令:openssl genrsa -out server.key 1024

        在bin目錄中生成server.key文件

(b)生成簽署申請

        執行命令:openssl req -new -out server.csr -key server.key

  在bin目錄中生成server.csr文件,在執行以上命令時會提示輸入相關信息,其中 Common Name <eg,YOUR name>[] 需要與配置文件中的ServerName一致,否則apache啟動時將會報錯。       

Country Name<2 letter code>[AU] : cn
State or Province Name <full name> [Some-State] : jangsu
Locality Name<eg , city>[] : nanjing
Oraganization Name <eg,company> [Internet Widgits Pty Ltd]: epms.cwp
Organizational Unit Name <eg,section> [] epms
Common Name<eg, YOUR name>[]:ServerName
Email Address []: ..................................
..................................................................................
A challenge password []: (可不輸入)

 (c)生成CA的key文件

         執行命令:openssl genrsa -out ca.key 1024

         在目錄bin下生成ca.key文件

(d) 生成CA自簽署證書

   執行命令:openssl req -new -x509 -days 365 -key ca.key -out ca.crt

      在目錄bin下生成ca.crt文件

(e)生成CA的服務器簽署證書

執行命令:openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key

在這里報錯了,按照網上的說法新建相應的文件夾,再執行一次就可以了

在bin下新建demoCA文件夾                     =>bin/demoCA
在demoCA下新建index.txt                 =>bin/demoCA/index.txt
在demoCA下新建serial.txt,其內容為01,重命名刪除.txt   =>bin/demoCA/serial
在demoCA下新建newcert文件夾               =>sbin/demoCA/newcerts

 3修改httpd-ssl.conf文件

(a)根據需要修改httpd-ssl.conf的默認端口號“443”,這里將所有的443修改為“6044”,同時修改ServerName。

<VirtualHost _default_:6044>          
ServerName  ........................:6044

 (b) 修改相關證書路徑,把路徑設置為conf下的key目錄,把生成的證書放進這個目錄

SSLCertificateFile    xxx/conf/key/server.crt    (服務器證書的位置) 
SSLCertificateKeyFile    xxx/conf/key/server.key (服務器私鑰的位置) 
SSLCACertificateFile    xxx/key/conf/ca.crt      (CA根證書的位置,進行客戶端驗證時需要)

(c) 取消注釋

#SSLVerifyClient require               (去掉前面的‘#’號,進行客戶端驗證時需要) 
#SSLVerifyDepth  1                     (去掉前面的‘#’號,把10改為1,進行客戶端驗證時需要)

(d) 選擇性修改,如果在運行時報錯,可修改SSLSessionCache再執行

修改前:

#SSLSessionCache         "dbm:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache"
SSLSessionCache        "shmcb:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300

修改后:

SSLSessionCache         "dbm:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache"
#SSLSessionCache        "shmcb:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300

4、重啟apache,執行兩個命令net stop Apache2.2net start Apache2.2,瀏覽器中輸入https//..............:6044頁面會提示 It works!

5、修改httpd-vhosts.conf 設置反向代理,重啟apache,瀏覽器中輸入https//..............:6044頁面會跳轉到相應的代理頁面(注意DocumentRoot路徑要存在)

NameVirtualHost *:6044

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:6044>
   DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/docs/"
   ServerName ......:6044   
   SSLEngine on  
   SSLProxyEngine on
   SSLCertificateFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/key/server.crt"
   SSLCertificateKeyFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/key/server.key"
   ProxyRequests Off     
  <Proxy *>
  Order deny,allow
  Allow from all
  </Proxy>
   ProxyPass / http://....../
   ProxyPassReverse / http://....../
</VirtualHost>

6、假如遇到apache無法啟動的時候,可以選我的電腦-》管理-》事件檢查器-》應用程序日志,打開apache的錯誤報告,會有提示哪里出錯了,一般都可以找到原因,

可以啟動,但無法映射到對應頁面,可以命令中輸入httpd 會提示相應的錯誤。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM