Quantcast
Channel: 容器云计算,Devops,DBA,网络安全。
Viewing all articles
Browse latest Browse all 780

Apache Httpd 开启 HTTPS 和 HTTP/2

$
0
0
前言 
 
 
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 的支持。
  1. 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 源支持。
  1. add-apt-repository ppa:ondrej/apache2apt-get updateapt-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 的支持,可以放心使用。
  1. dnf install httpd openssl
 
 
 
启用 mod_http2 模块 
 
 
终端中输入: 
  1. a2enmod http2 # 启用 mod_http2 模块

  2. service httpd restart # RHEL、CentOS、Fedora
  3. service apache2 restart # Debian、Ubuntu
 
 
 
编译 
 
 
 
核心组件依赖 
 
[font=-apple-system, BlinkMacSystemFont, &quot]适合 Ubuntu 16.04 or later 和 Debian 9 or later 
  1. apt-get installl nghttp2 libnghttp2-dev openssl #Debian、Ubuntu

  2. 未来或许可以用
  3. yum install nghttp2 libnghttp2-dev openssl #RHEL、CentOS
 
 
 
核心组件不依赖 
 
 
 
OpenSSL 
 
  1. wget https://www.openssl.org/source/openssl-1.1.0c.tar.gz
  2. tar xzf openssl-1.1.0c.tar.gz
  3. cd openssl-1.1.0c
  4. ./config --prefix=/usr/local/openssl
  5. make && make install
 
 
 
nghttp2 
 
  1. wget https://github.com/nghttp2/nghttp2/releases/download/v1.17.0/nghttp2-1.17.0.tar.gz
  2. tar xzf nghttp2-1.17.0.tar.gz
  3. cd nghttp2-1.17.0
  4. ./configure --prefix=/usr/local/nghttp2
  5. make && make install
 
 
 
编译 Apache Httpd 
 
 
在原来的编译参数上加入如下参数: 
  1. –enable-http2
 
 
让 Apache Httpd 可以实现 HTTP/2 协议 
  1. --enable-ssl
 
 
开启 mocd_ssl 的支持 
  1. –with-nghttp2=/usr/local/nghttp2
 
 
指定 nghttp2库 的位置,如果是利用系统以来的就不用这个 
  1. --with-ssl=/usr/local/openssl
 
 
指定 openssl 库 的位置,如果是利用系统以来的就不用这个 
 
设置 
 
 
在 httpd.conf 中,或者 /etc/enabled-sites/ 目录下添加或新建,具体文档自己参考。 
在相关虚拟主机的 443 端口中加入: 
  1. ProtocolsHonorOrder On
  2. Protocols h2 h2c http/1.1
 
 
即可开启 HTTPS 和 h2 了,完整的参考可以这里: 
  1. <VirtualHost *:443>

  2.     ...
  3.     
  4.     SSLEngine on
  5.     SSLCertificateFile      /path/to/crt
  6.     SSLCertificateKeyFile   /path/to/key
  7.     SSLCACertificateFile    /path/to/ca_certs_for_client_authentication
  8.     ProtocolsHonorOrder On
  9.     Protocols h2 h2c http/1.1
  10.     
  11.     # HSTS
  12.     Header always set Strict-Transport-Security "max-age=15768000"
  13.     
  14.     # modern configuration, tweak to your needs
  15.       SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
  16.       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
  17.       SSLHonorCipherOrder     on
  18.       SSLCompression          off
  19.       SSLSessionTickets       off

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

  25.     ...
  26.     
  27. </VirtualHost>
 

Viewing all articles
Browse latest Browse all 780

Trending Articles


Vimeo 10.7.1 by Vimeo.com, Inc.


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


Presence Quotes – Positive Quotes


EASY COME, EASY GO


Love with Heart Breaking Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


FORTUITOUS EVENT


Pokemon para colorear


Sapos para colorear


Smile Quotes


Letting Go Quotes


Love Song lyrics that marks your Heart


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Long Distance Relationship Tagalog Love Quotes