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

2、cd F:Apachebin

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,报错的话就查找相应原因解决

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!