zoukankan      html  css  js  c++  java
  • Windows 下配置 Apache 支持 https

    1、打开cmd ,输入  F:  // 切换到Apache安装路径,我的Apache安装目录在 F盘

    2、cd F:Apachein

    3、set "openssl_conf = F:Apacheconfopenssl.cnf"

      临时设置openssl_conf路径,也可在环境变量中建新项目,键为 OPENSSL_CONF,值为 F:Apacheconfopenssl.cnf (看自己的安装路径),不然在生成key时会报“WARNING: can't open config file: c:/openssl-1.0.2j-win64/ssl/openssl.cnf”错误。

    4、openssl genrsa -out server.key 1024  // 生成私密key

    5、copy server.key server.key.org  // 复制server.key 防止启动Apache要密码

    6、openssl rsa -in server.key.org -out server.key

    7、openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt  // 生成证书,会要求填写国家、省份、城市、域名、邮箱等信息

    8、配置Apahce  !!!  核心步骤 !!!

    8.1 在http.conf文件中去掉下面代码前的#号

    #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so #LoadModule ssl_module modules/mod_ssl.so #Include conf/extra/httpd-ssl.conf
    8.2 修改 F:/Apache/conf/extra/httpd-ssl.conf 文件

    <VirtualHost _default_:443> DocumentRoot "F:/Apache/htdocs/ushark.net" ServerName www.ushark.net:443 SSLCertificateFile "F:/Apache/bin/server.crt" SSLCertificateKeyFile "F:/Apache/bin/server.key" </VirtualHost>

    9、配置http自动跳转到https,在 httpd-vhosts.conf 文件中编辑如下内容,也可参考这篇文章:https://wiki.apache.org/httpd/RedirectSSL

    <VirtualHost *:80>
      DocumentRoot "F:/Apache/htdocs/ushark.net"
      ServerName www.ushark.net
      Redirect / https://www.ushark.net/  # !!! 核心代码 !!!
    </VirtualHost>

    10、httpd -k restart  // 重新启动Apache,报错的话就查找相应原因解决

  • 相关阅读:
    64最长和谐子序列(594)
    63找到字符串中所有字母异位词(438)
    62有效的数独(36)
    10.10
    9.27作业
    9.27
    9.26
    9.25
    9.18学习内容
    9.17作业
  • 原文地址:https://www.cnblogs.com/gentsir/p/8358544.html
Copyright © 2011-2022 走看看