米饭粑 米饭粑
  • 首页
  • 好物推荐
    • 干货分享
    • 好物推荐
    • 免费资源
    • 非专业测评
  • 技术架构
    • Linux
    • HTTPS
    • Windows Server
  • 关于米饭
  • 教程&更多
    • 更多教程
    • 资讯新闻
    • 琐琐碎碎
    • 打赏米饭
    • 阿里云Ping
  • 友情链接
首页 › 技术架构 › HTTPS › Apache Httpd 开启 HTTPS 和 HTTP/2

Apache Httpd 开启 HTTPS 和 HTTP/2

妙正灰
5年前HTTPS阅读 7,240

前言

HTTPS 即将在 2017 年获得广泛的普及和支持,这里介绍一下 Apache Httpd 设置 HTTPS 并开启 HTTP/2 (以下会简称 h2)的教程。

不过呢,在目前的条件下,个人还是建议一些强 Apache Httpd 的环境例如 LAMP 可以考虑前面加一层 Nginx,来更灵活的实现 HTTPS + HTTP/2 的新特性,例如目前 Apache Httpd 对 CHACHA20-POLY1305 的算法弄起来就灵活。

准备

  1. Apache Httpd ≥ 2.4.17 ,Apache Httpd 从 2.4.17 开始支持 mod_http2 ,并且编译时加入 --enable-http2
  2. OpenSSL ≥ 1.0.2 浏览器客户端例如 Chrome 51(2016 年 5 月 31 日发布)之后,已经不支持对没有 ALPN 协议网站的 h2 支持,OpenSSL 1.0.2 起开始支持 ALPN 协议。
  3. nghttp2 ≥ 1.12,其为是基于 C 实现的 HTTP/2 库,为实现 Apache Httpd 支持 h2 所必须
  4. (编译、Win二进制)Apache Httpd ≥ 2.4.25 ,如果是自己编译或者 Win 采用二进制编译包的 Apache Httpd 并且开启 mod_http2 支持,版本必须大于 2.4.25,因为之前的版本存在 DDOS 漏洞

非编译

Debian

Debian 在 stretch(9)才有 Apache Httpd(apache2) ≥ 2.4.17 (已经编译 mod_http2 模块)和 OpenSSL ≥ 1.0.2 的支持。

apt-get install apache2 openssl

Ubuntu

Ubuntu 截止发文,包括 xenial(16.04)和 yakkety(16.10)中的 Apache Httpd(apache2)2.4.18 并没有编译编译 mod_http2 模块,也没提供 mod_http2 的二进制包。

不过大神,ondrej 则提供了最新的 Apache Httpd(apache2)和 mod_http2 的二进制包还有 nghttp2 的 PPA 源支持。

add-apt-repository ppa:ondrej/apache2
apt-get update
apt-get install apache2 openssl

RHEL、CentOS

截止发文切仍受支持的 RHEL、CentOS 5、6、7 均不提供 Apache Httpd(apache2) ≥ 2.4.17 和 OpenSSL ≥ 1.0.2 的支持,也没有提供支持的第三放软件源支持。 请参考下面的 编译 方法。

Fedora

截止发文,最新的 Fedora 25 版本,已经提供 Apache Httpd(apache2) ≥ 2.4.17 (已经编译 mod_http2 模块)和 OpenSSL ≥ 1.0.2 的支持,可以放心使用。

dnf install httpd openssl

启用 mod_http2 模块

在终端中输入:

a2enmod http2 # 启用 mod_http2 模块

service httpd restart # RHEL、CentOS、Fedora
service apache2 restart # Debian、Ubuntu

编译

核心组件依赖

适合 Ubuntu 16.04 or later 和 Debian 9 or later

apt-get installl nghttp2 libnghttp2-dev openssl #Debian、Ubuntu

未来或许可以用
yum install nghttp2 libnghttp2-dev openssl #RHEL、CentOS

核心组件不依赖

OpenSSL

wget https://www.openssl.org/source/openssl-1.1.0c.tar.gz
tar xzf openssl-1.1.0c.tar.gz
cd openssl-1.1.0c
./config --prefix=/usr/local/openssl
make && make install  

nghttp2

wget https://github.com/nghttp2/nghttp2/releases/download/v1.17.0/nghttp2-1.17.0.tar.gz
tar xzf nghttp2-1.17.0.tar.gz
cd nghttp2-1.17.0
./configure --prefix=/usr/local/nghttp2
make && make install

编译 Apache Httpd

在原来的编译参数上加入如下参数:

–enable-http2
让 Apache Httpd 可以实现 HTTP/2 协议

--enable-ssl
开启 mocd_ssl 的支持

–with-nghttp2=/usr/local/nghttp2
指定 nghttp2库 的位置,如果是利用系统以来的就不用这个

--with-ssl=/usr/local/openssl
指定 openssl 库 的位置,如果是利用系统以来的就不用这个

设置

在 httpd.conf 中,或者 /etc/enabled-sites/ 目录下添加或新建,具体文档自己参考。

在相关虚拟主机的 443 端口中加入:

ProtocolsHonorOrder On
Protocols h2 h2c http/1.1

即可开启 HTTPS 和 h2 了,完整的参考可以这里:

<VirtualHost *:443>

    ...
    
    SSLEngine on
    SSLCertificateFile      /path/to/crt
    SSLCertificateKeyFile   /path/to/key
    SSLCACertificateFile    /path/to/ca_certs_for_client_authentication
    ProtocolsHonorOrder On
    Protocols h2 h2c http/1.1
    
    # HSTS
    Header always set Strict-Transport-Security "max-age=15768000"
    
    # modern configuration, tweak to your needs
      SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
      SSLCipherSuite          ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-     SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-   AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-    RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
      SSLHonorCipherOrder     on
      SSLCompression          off
      SSLSessionTickets       off

      # OCSP Stapling, only in httpd 2.3.3 and later
      SSLUseStapling          on
      SSLStaplingResponderTimeout 5
      SSLStaplingReturnResponderErrors off
      SSLStaplingCache        shmcb:/var/run/ocsp(128000)

    ...
    
</VirtualHost>
Apache Httpd h2 HTTP2 Httpd HTTPS nghttp2
赞(1)
Nginx 开启 Certificate Transparency 保障证书安全
上一篇
生成、签署 ECC 证书,Apache Httpd 部署双证书教程
下一篇

评论已关闭

标签
Appnode Brotli CDN CentOS CentOS8 Debian DNS ECC ECS Ghost HTTP2 HTTPS IIS IPV6 Linux LiteSpeed MariaDB MySQL Nginx OLS OpenLiteSpeed OpenResty OSS PageSpeed PHP PHP7 QUIC Redis RHEL RHEL8 SSL TokuDB Ubuntu Windows Server 2016 Wordpress 云服务器 升级 域名 对象存储 微软 数据库 百度 笔记本 阿里云 阿里云ACP
归档
4月4日,全国哀悼,简单CSS代码将网站变成灰色
2年前
793 0
使用如下姿势预防阿里云 CDN 产生天价账单
2年前
1,031 2
阿里云IPv6实践,从云服务到云安全
3年前
813 3
不花一分钱构建阿里云上第零步安全体系
3年前
814 3
1
  • 1
Copyright © 2011-2022 米饭粑. Designed by nicetheme.
浙ICP备15006212号-1
  • 首页
  • 教程
  • 好物
  • 关于
  • 链接
  • 打赏
# 402 # # 113 # # 546 # # 548 # # 460 #
妙正灰
文科屌丝伪IT男一枚.
337
文章
385
评论
449
喜欢