作中经常会遇到多个站点实现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站点的更多相关文章

  1. windows apache 配置多个服务站点

    原文 方法一:多个APACHE服务 更改第一个站点的根目录: 在文件Apache2.2/conf/httpd.conf中查找 DocumentRoot 属性,将后面的路径改为你的主站点的路径, 如:D ...

  2. Apache配置多端口多站点

    配置httpd.conf 监听多个端口 复制代码 代码如下:# Listen: Allows you to bind Apache to specific IP addresses and/or # ...

  3. windows下apache配置ssl(https)服务器

    SSl是为Http传输提供安全的协议,通过证书认证来确保客户端和网站服务器之间的数据是安全, 可以通过apache自带的openssl进行配置: 步骤如下: 1.安装有openssl模板的apache ...

  4. windows apache 配置多个服务 站点 Apache Service Monitor

    把Apache安装为多个Window NT服务 ~~~ 可以在 services.msc中查看到1. 在DOS下跳到Apache安装目录里的bin目录(~~~或者用path命令 把apache的安装目 ...

  5. Linux下Apache配置SSL支持https

    参考:http://www.thinksaas.cn/group/topic/280017/ 生成证书过程如下 Step :生成服务器密钥: mkdir -p /etc/pki/test cd /et ...

  6. Apache 配置 http 转 https

    <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} !^443$ Rewr ...

  7. apache配置多域名多站点记录

    <VirtualHost *:80>  DocumentRoot "/mnt/web/www.*.cn"  ServerName www.*.cn  ErrorLog ...

  8. apache配置https重定向

    apache配置https重定向 一.总结 一句话总结: 网上找不到答案的原因是因为没有精准的描述问题,没有把问题描述清楚:尽量把关键词描述清楚 1.apache将80端口重定向443的具体步骤(在 ...

  9. websocket + TP5.1 + apache 配置步骤

    websocket + TP5.1 + apache 配置步骤 1. https ssl配置好 2. 检查php环境是否满足Workerman要求 curl -Ss http://www.worker ...

随机推荐

  1. USACO The Clocks

    操作间没有次序关系,同一个操作最多重复3次... 可以直接暴力... The Clocks IOI'94 - Day 2 Consider nine clocks arranged in a 3x3 ...

  2. 【大数据系列】使用api修改hadoop的副本数和块大小

    package com.slp.hdfs; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.h ...

  3. redhat vi 命令

    转载:http://www.cnblogs.com/zhanglong0426/archive/2010/10/07/1845268.html http://blog.sina.com.cn/s/bl ...

  4. 题目1446:Head of a Gang(并查集操作)

    题目链接:http://ac.jobdu.com/problem.php?pid=1446 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  5. openvpn 负载均衡方案

    这些方案的前提是,vpnserver的key都是一样的.方案1在openvpn客户端设两个配置文件,我们自己手动去连接去选择方案2在openvpn 的配置文件里面加个随机参数remote 8.8.8. ...

  6. 熟悉使用ConfigParser库读写配置文件

    Python的配置文件 配置文件 setting.ini文件是一个纯文本 [DataBase1] username = admin passwors = root [DataBase2] hostna ...

  7. Unity3D Shader描边效果

    Shader "Custom/RimColor" { Properties { _MainTex ("Base (RGB)", 2D) = "whit ...

  8. Python安装模块出错(No module named setuptools)解决方法

    Python第三方模块中一般会自带setup.py文件,在Windows环境下,我们只需要在命令行中使用以下命令即可自动化安装 python setup.py install 安装的过程中有可能会出现 ...

  9. 公钥基础设施体系和EJBCA的一些概念

    最近一段时间的在公司做的事情是: 1. 为公司的一些线上系统启用https(使用nginx反向代理的方式来实现,之前的应用无需做改动) 2.为符合规则的用户颁发数字证书(自建CA来实现,目前的用途是给 ...

  10. Unity3D 记第一次面试

    事情是发生在2014-03-05 周三下午 在群里面看到上海艺游急聘Unity3D开发工程师,就整理了下简历投了去!直到接到电话通知我去面试才知道 我之前是有投了简历!太忙了 以至于真的忘了,不过那个 ...