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

avatar
作者
筋斗云
阅读量:0

本次实验背景:
完全参考官方 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 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!