Apache 配置多个HTTPS站点
作中经常会遇到多个站点实现https访问,并指向同一个网页,本文将详解如何在Centos 环境下配置Apache多站点实现HTTPS访问。
准备工作
OS:CentOS release 6.8 (Final)
Web:Apache
安装Apache
1、安装Apache
[root@node1 ~]# yum install httpd -y
2、启动服务
[root@node1 ~]# service httpd start
Starting httpd: [ OK ]
[root@node1 ~]#
3、修改测试页面
[root@node1 ~]# cat /var/www/html/index.html
<h1>
Apache Test Page~
</h1>
4、测试访问

实现HTTPS访问
1、安装SSL模块
[root@node1 ~]# yum install mod_ssl -y
2、检测
[root@node1 ~]# cd /etc/httpd/modules/
[root@node1 modules]# ll | grep ssl
-rwxr-xr-x 1 root root 181872 Oct 20 2017 mod_ssl.so
3、上传证书文件
这里我们可以到各大厂商去申请免费证书,可满足个人网站的需求,如企业网站,建议购买企业收费证书;
[root@node1 ~]# cd /etc/httpd/
[root@node1 httpd]# mkdir ssl/default
[root@node1 httpd]# cd ssl/default
[root@node1 default]# rz
[root@node1 default]# ll
total 12
-rw-r--r-- 1 root root 1683 Apr 13 22:26 1_root_bundle.crt
-rw-r--r-- 1 root root 2008 Apr 13 22:26 2_domaintest.cn.crt
-rw-r--r-- 1 root root 1678 Apr 13 22:26 3_domaintest.cn.key
[root@node1 default]#
4、修改配置
[root@node1 ~]# cd /etc/httpd/conf.d/
[root@node1 conf.d]# ls
README ssl.conf welcome.conf
[root@node1 conf.d]# vim ssl.conf
LoadModule ssl_module modules/mod_ssl.so
Listen 443
<VirtualHost *:443>
DocumentRoot "/var/www/html"
ServerName domaintest.cn
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/default/2_domaintest.cn.crt
SSLCertificateKeyFile /etc/httpd/ssl/default/3_domaintest.cn.key
SSLCertificateChainFile /etc/httpd/ssl/default/1_root_bundle.crt
</VirtualHost>
| 配置文件参数 | 说明 |
|---|---|
| LoadModule | 加载SSL模块 |
| Listen | 监听443端口 |
| DocumentRoot | 网页目录 |
| ServerName | 站点域名 |
| SSLEngine on | 启用SSL功能 |
| SSLCertificateFile | 证书文件 |
| SSLCertificateKeyFile | 私钥文件 |
| SSLCertificateChainFile | 证书链文件 |
5、重启服务
[root@node1 ~]# httpd -t
Syntax OK 可以先试用httpd -t 检测一下配置文件是否正确,然后再重启服务; [root@node1 ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
6、检测端口是否监听
[root@node1 conf.d]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:443 *:*
[root@node1 conf.d]#
配置多个HTTPS站点
1、上传证书文件
[root@node1 ~]# cd /etc/httpd/ssl/
[root@node1 ssl]# mkdir web
[root@node1 ssl]# cd web/
[root@node1 web]# rz
2、修改配置文件
LoadModule ssl_module modules/mod_ssl.so
Listen 443
NameVirtualHost *:443
# 第一个虚拟主机
<VirtualHost *:443>
DocumentRoot "/var/www/html"
ServerName domaintest.cn
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/default/2_domaintest.cn.crt
SSLCertificateKeyFile /etc/httpd/ssl/default/3_domaintest.cn.key
SSLCertificateChainFile /etc/httpd/ssl/default/1_root_bundle.crt
</VirtualHost>
#第二个虚拟主机
<VirtualHost *:443>
DocumentRoot "/var/www/html"
ServerName web.domaintest.cn
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/web/2_web.domaintest.cn.crt
SSLCertificateKeyFile /etc/httpd/ssl/web/3_web.domaintest.cn.key
SSLCertificateChainFile /etc/httpd/ssl/web/1_root_bundle.crt
</VirtualHost>
3、重启服务
[root@node1 conf.d]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@node1 conf.d]#
4、测试
Apache 配置多个HTTPS站点的更多相关文章
- windows apache 配置多个服务站点
原文 方法一:多个APACHE服务 更改第一个站点的根目录: 在文件Apache2.2/conf/httpd.conf中查找 DocumentRoot 属性,将后面的路径改为你的主站点的路径, 如:D ...
- Apache配置多端口多站点
配置httpd.conf 监听多个端口 复制代码 代码如下:# Listen: Allows you to bind Apache to specific IP addresses and/or # ...
- windows下apache配置ssl(https)服务器
SSl是为Http传输提供安全的协议,通过证书认证来确保客户端和网站服务器之间的数据是安全, 可以通过apache自带的openssl进行配置: 步骤如下: 1.安装有openssl模板的apache ...
- windows apache 配置多个服务 站点 Apache Service Monitor
把Apache安装为多个Window NT服务 ~~~ 可以在 services.msc中查看到1. 在DOS下跳到Apache安装目录里的bin目录(~~~或者用path命令 把apache的安装目 ...
- Linux下Apache配置SSL支持https
参考:http://www.thinksaas.cn/group/topic/280017/ 生成证书过程如下 Step :生成服务器密钥: mkdir -p /etc/pki/test cd /et ...
- Apache 配置 http 转 https
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} !^443$ Rewr ...
- apache配置多域名多站点记录
<VirtualHost *:80> DocumentRoot "/mnt/web/www.*.cn" ServerName www.*.cn ErrorLog ...
- apache配置https重定向
apache配置https重定向 一.总结 一句话总结: 网上找不到答案的原因是因为没有精准的描述问题,没有把问题描述清楚:尽量把关键词描述清楚 1.apache将80端口重定向443的具体步骤(在 ...
- websocket + TP5.1 + apache 配置步骤
websocket + TP5.1 + apache 配置步骤 1. https ssl配置好 2. 检查php环境是否满足Workerman要求 curl -Ss http://www.worker ...
随机推荐
- SNAT DNAT MASQUERADE 区别
SNAT,DNAT,MASQUERADE都是NATMASQUERADE是SNAT的一个特例SNAT是指在数据包从网卡发送出去的时候,把数据包中的源地址部分替换为指定的IP,这样,接收方就认为数据包的来 ...
- php pear包打包方法
一)首先下载工具onion 浏览器打开,服务器上wget测试无法正常下载 地址:https://raw.github.com/c9s/Onion/master/onion 二)在临时目录下,建立相关目 ...
- vue经验 - 细节小知识点汇总(更新中...)
1. $refs 数据这么绑定的: 然后在created中抛出来,猜猜看看打印的是两个什么? 结果如下: 第一个跑出来了,第二个,却undefiend,没有东西?!... 后来去官网查看$refs的解 ...
- 题目1461:Tempter of the bone(深度优先遍历DFS)
题目链接:http://ac.jobdu.com/problem.php?pid=1461 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 题目1003:A+B(按逗号分隔的A+B)
题目链接:http://ac.jobdu.com/problem.php?pid=1003 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- [原]rpm安装rpm-package报错:Header signature NOKEY 和 error: Failed dependencies:
以前经常遇到这个问题,一直未有记录,今天记录下来: 在安装rpm包的时候报错误如下: Question 1: warning: *.rpm: Header V3 DSA signature: NOKE ...
- window上安装pymysql
date: 2018-11-26 18:54:04 安装: cmd: pip install pymysql 验证: cmd: python >>import pymysql 不报错即 ...
- 使用COSBench工具对ceph s3接口进行压力测试
一.COSBench安装 COSBench是Intel团队基于java开发,对云存储的测试工具,全称是Cloud object Storage Bench 吐槽下,貌似这套工具是intel上海团队开发 ...
- CSS 盒子模型 二
Sublime 快捷键: 文件保存后,输入 html:xt + tab ,补全html html:xt <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...
- java的HashSet 原理
概括:HashSet 以HashMap为基础,判断HashSet 中元素是否存在和重复,先把该元素经过hashcode()等方法计算之后得到的值作为key值, 然后比较该key值是否存在和重复(把该元 ...