Apache 配置多个HTTPS站点

工作中经常会遇到多个站点实现https访问,并指向同一个网页,本文将详解如何在Centos 环境下配置Apache多站点实现HTTPS访问。

准备工作

OS:CentOS release 6.8 (Final)
Web:Apache

安装Apache

1、安装Apache

[[email protected] ~]# yum install httpd -y

2、启动服务

[[email protected] ~]# service  httpd start
Starting httpd:                                            [  OK  ]
[[email protected] ~]# 

3、修改测试页面

[[email protected] ~]# cat /var/www/html/index.html
<h1>
Apache Test Page~
</h1>

4、测试访问

实现HTTPS访问

1、安装SSL模块

[[email protected] ~]# yum install mod_ssl -y

2、检测

[[email protected] ~]# cd /etc/httpd/modules/
[[email protected] modules]# ll | grep ssl
-rwxr-xr-x 1 root root 181872 Oct 20  2017 mod_ssl.so

3、上传证书文件
这里我们可以到各大厂商去申请免费证书,可满足个人网站的需求,如企业网站,建议购买企业收费证书;

[[email protected] ~]# cd /etc/httpd/
[[email protected] httpd]# mkdir ssl/default
[[email protected] httpd]# cd ssl/default
[[email protected] default]# rz
[[email protected] 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
[[email protected] default]# 

4、修改配置

[[email protected] ~]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# ls
README  ssl.conf  welcome.conf
[[email protected] 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、重启服务

[[email protected] ~]# httpd -t
Syntax OK

可以先试用httpd -t 检测一下配置文件是否正确,然后再重启服务;

[[email protected] ~]# service  httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

6、检测端口是否监听

[[email protected] 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                     *:*
[[email protected] conf.d]# 

7、测试访问

  • 建议使用google浏览器进行测试访问,f12查看,会显示“This page is secure (valid HTTPS).”,说明证书配置正确;

    配置多个HTTPS站点

    1、上传证书文件

    [[email protected] ~]# cd /etc/httpd/ssl/
    [[email protected] ssl]# mkdir web
    [[email protected] ssl]# cd web/
    [[email protected] 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、重启服务

    [[email protected] conf.d]# service  httpd restart
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]
    [[email protected] conf.d]# 

    4、测试访问

到这里,Apache多站点https就实现了~

原文地址:http://blog.51cto.com/guoxh/2114630

时间: 2024-08-11 18:07:42

Apache 配置多个HTTPS站点的相关文章

Apache配置SSL 实现https访问

本次坏境:CA和apache为同一台主机 先使本机作为CA服务端: [[email protected]~]#yum -y install openssl openssl-devel [[email protected]~]#vi /etc/pki/tls/openssl.cnf [ CA_default ] dir = ../../CA 改为: [ CA_default ] dir= /etc/pki/CA 为了减少不必要的重复操作,可以预先定义[ req_distinguished_name

windows apache 配置多个服务站点

原文 方法一:多个APACHE服务 更改第一个站点的根目录: 在文件Apache2.2/conf/httpd.conf中查找 DocumentRoot 属性,将后面的路径改为你的主站点的路径, 如:D:/www/web1 为第二个Apache服务建立配置文件: 复制并重命名httpd.conf为web2.conf(举个例子而已,也可以叫my.conf等等), 修改 web2.conf中的 Listen 8080(原来为80) ServerName localhost:8080(原来为80) Do

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

SSl是为Http传输提供安全的协议,通过证书认证来确保客户端和网站服务器之间的数据是安全, 可以通过apache自带的openssl进行配置: 步骤如下: 1.安装有openssl模板的apache,大多数都会有,判断有没有 只需要查看 apache\bin 下有没有 openssl.exe 运行程序: 2.配置 apache/conf/httpd.conf 文件,如下: #LoadModule ssl_module modules/mod_ssl.so #Include conf/extra

Apache 配置 http 转 https

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L] RewriteEngine On RewriteCond %{HTTP_HOST} www.wqj17.cn [NC] RewriteRule ^(.*)$ http://wqj17.cn/$1 [L,R=301]

Windows下Apache配置SSL以支持https及出错的解决办法

步骤一:安装apache,使其支持SSL,并安装php 1.安装配有SSL模块的apache,apache_2.2.8-win32-x86-openssl-0.9.8g 2.配置apache以支持SSL: 1)打开apache的配置文件conf/httpd.conf LoadModule ssl_module modules/mod_ssl.so Include conf/extra/httpd-ssl.conf 去掉两行前面的# 2)注意修改httpd-ssl.conf 文件里的两个字段: S

apache配置virtualhost https(ssl)

1.申请免费ssl证书 freessl上可以免费申请,按提示操作即可. https://freessl.cn/ 2.上传证书到服务器. 3.配置apache:直接上代码,改一下里面的三个路径即可. <VirtualHost *:443> DocumentRoot /var/www/xxx ServerName xxx.xxx.com ServerAlias xxx.xxx.com ErrorLog "/var/log/httpd/xxx-error.log" CustomL

PHP100-第二讲 PHP5.4 Apache Mysql 搭配与多站点配置详解

PHP5.4环境搭配基本流程 关于新版的PHP环境的一个搭配过程,与之前的 php5.3.x 没有太大差异, 这次使用的环境搭配组建包括: httpd-2.2.21-win32-x86 mysql-5.5.18-win32 php-5.4.0RC4-Win32-VC9-x86 //================= LoadModule php5_module "c:/www/php54/php5apache2_2.dll" AddType application/x-httpd-ph

Apache 配置 https

## Apache 配置 https > Apache 版本: **2.4.10** Linux 版本 : **Debian** ### 安装Apache控制台命令:` sudo apt-get install apache2 `安装好了Apache2会自动启动,但是自动启动的不包含https仅仅是http **默认的配置路径** Apache配置文件路径: ` cd /etc/apache2/`Apache默认日志路径: `cd /var/log/apache2` ### 配置https###

Apache配置HTTPS功能

apache配置https 一.yum 安装openssl和openssl-devel,httpd-devel 二.生成证书(也可以从公司的证书颁发机构获取): #建立服务器密钥  openssl genrsa -des3 1024  > /usr/local/apache/conf/server.key    # 从密钥中删除密码(以避免系统启动后被询问口令) openssl rsa -in /usr/local/apache/conf/server.key > /usr/local/apa