win2022服务器apache配置https(ssl)真实环境实验(避坑之作)不依赖宝塔小皮等集成环境

本次实验背景:
完全参考官方 https://cloud.tencent.com/document/product/400/4143 文档流程,没有搞定,于是写下避坑之作。

服务器:腾讯云轻量应用服务器
操作系统: Windows Server 2022 DataCenter 64bit CN
apache版本:Apache 2.4.59

证书下载及存放

  1. 下载证书
    这里完全按照官方的来
    在这里插入图片描述
  2. 证书存放
    如下图所示,为方便管理和引用,我在服务器的conf下新建了目录ssl,把需要用到的三个证书(除CSR外)放到这里
    在这里插入图片描述

一、开启ssl配置文件

  1. 使用文本编辑器,打开 Apache 服务器 conf 目录下 httpd.conf 文件,并删除以下字段前 # 注释符。
#LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-ssl.conf

在这里插入图片描述
在这里插入图片描述
2. 将httpd-ssl.conf中虚拟机部分代码注释
在这里插入图片描述
在这里插入图片描述

二、配置虚拟机

打开Apache24\conf\extra\目录,将httpd-vhosts.conf复制一份备份,清空httpd-vhosts.conf内容加入下面内容,*****包含作者真实域名信息,打了马赛克。

<VirtualHost *:80>
    DocumentRoot "C:\WF\www\html\****"
   <Directory "C:\WF\www\html\****">
        RewriteEngine on
        RewriteCond %{SERVER_PORT} !^443$
        RewriteRule ^(.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
    </Directory>
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot "C:\WF\www\html\****"
    ServerName ****.com
    ServerAlias www.****.com
    #ssl
    SSLEngine on
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory "${SRVROOT}/cgi-bin">
    SSLOptions +StdEnvVars
    </Directory>
    #ssl-key
    SSLCertificateFile "${SRVROOT}/conf/ssl/****.com.crt"
    SSLCertificateKeyFile "${SRVROOT}/conf/ssl/****.com.key"
    SSLCertificateChainFile "${SRVROOT}/conf/ssl/root_bundle.crt"
    #ssl-key-END
    BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

    #   Per-Server Logging:
    #   The home of a custom SSL log file. Use this when you want a
    #   compact non-error SSL logfile on a virtual host basis.
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

在这里插入图片描述

三、测试配置文件+重启apache服务

net stop apache
httpd -t
net start apache
  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值