• 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 FoundationApache2.2in

    设置OPENSSL_CONFIG配置,执行命令 set OPENSSL_CONF=..confopenssl.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 会提示相应的错误。

  • 相关阅读:
    C++ 知识回顾总结 -- queue 队列容器
    C++标准模板库(STL)之Stack
    c++优先队列(priority_queue)用法详解
    数组中超过一半的数
    【LeetCode】93. Restore IP Addresses 【面试题】
    atoi()和stoi()的区别----数字字符串的处理
    C++中substr函数的用法
    基本排序算法 【转载】
    平衡数
    python中Sting字符串
  • 原文地址:https://www.cnblogs.com/huxiaoli/p/6274347.html
Copyright © 2020-2023  润新知