主頁 >  其他 > 在 Qualys SSL Labs SSL 測驗中獲得 A+ 評級的秘技 2021 版

在 Qualys SSL Labs SSL 測驗中獲得 A+ 評級的秘技 2021 版

2021-12-10 06:23:01 其他

本系列文章將闡述主流應用交付控制器和主流 Web 服務器如何運行 HTTP/2 和 TLSv1.3 協議,以及如何在 SSL Test 中獲得 A+ 評級,

請訪問原文鏈接:https://sysin.org/blog/get-a-plus-rating-on-ssl-test/,查看最新版,原創作品,轉載請保留出處,

作者:gc(at)sysin.org,主頁:www.sysin.org

2021 年 8 月發布的 Windows Server 2022 正式支持 QUIC 和 TLS 1.3 相關特性,至此,主流產品已經全部支持 TLSv1.3 協議,

0. 概述

Qualys SSL Labs 簡介

Qualys,Inc.(NASDAQ:QLYS)是云安全和合規解決方案的先驅和領先提供商,在 100 多個國家擁有 6700 多個客戶,其中包括福布斯全球 100 強和財富 100 強中的大多數,QualysGuard 云平臺和集成解決方案套件通過按需提供關鍵的安全智能并自動化 IT 系統和 web 應用程式的全方位審核、法規遵從性和保護,幫助組織簡化安全操作并降低合規成本,Qualys 成立于 1999 年,與英國電信、戴爾安全工程、富士通、IBM、NTT、Symantec、Verizon 和 Wipro 等領先的托管服務提供商和咨詢機構建立了戰略合作關系,該公司還是云安全聯盟(CSA)的創始成員,

SSL Labs 推出的全球知名的 SSL 網站在線檢測工具,會對 HTTPS 網站的證書鏈、安全性、性能、協議細節進行全面檢測,檢測完畢后會進行打分,同時給出一份詳細的檢測報告和改進建議,

測驗網站:https://www.ssllabs.com/ssltest/

測驗規則概述

2020 年演算法變更

January 2020

主要是修改了 TLS 1.0 和 TLS 1.1 的評分標準,TLS 1.0 和 TLS 1.1 是分別于 1996 年和 2006 年發布的老版協議,使用的是弱加密演算法和系統,比如 SHA-1 和 MD5,這些演算法和系統十分脆弱,存在重大安全漏洞,容易受到降級攻擊的嚴重影響,而在 2008 年和 2017 年分別發布了協議的新版本,即 TLS 1.2 和 TLS 1.3,無疑更優于舊版本,使用起來也更安全,

2018 年,在春季 TLS 1.3 版本發布之后,蘋果、谷歌、Mozilla 和微軟四大瀏覽器制造商于 2018 年 10 月聯合宣布計劃在 2020 年初取消對 TLS 1.0 和 TLS 1.1 的支持,

主流瀏覽器客戶端都提供了禁用 TLS 1.0 和 TLS 1.1 協議的大致期限:

Browser Name Date
Microsoft IE and Edge First half of 2020
Mozilla Firefox March 2020
Safari/Webkit March 2020
Google Chrome January 2020

備注:由于受 COVID-19 影響,瀏覽器廠商推遲了 TLS 1.0 和 1.1 版本協議的淘汰時間,

Existing Grades Sample

Server Configuration Grade
TLS 1.2, TLS 1.1, TLS 1.0 + HSTS + No Warning + TLS_FALLBACK_SCSV A+
TLS 1.2, TLS 1.1, TLS 1.0 + HSTS + No Warning + No support for TLS_FALLBACK_SCSV A
TLS 1.2, TLS 1.1, TLS 1.0 + HSTS + Warnings + No support for TLS_FALLBACK_SCSV A-

Future Grades Sample

Server Configuration Grade
TLS 1.2, TLS 1.1, TLS 1.0 + HSTS + No Warning + TLS_FALLBACK_SCSV B
TLS 1.2, TLS 1.1, TLS 1.0 + HSTS + No Warning + No support for TLS_FALLBACK_SCSV B
TLS 1.2, TLS 1.1, TLS 1.0 + HSTS + Warnings + No support for TLS_FALLBACK_SCSV B
TLS 1.2 + HSTS + No Warning + TLS_FALLBACK_SCSV A+
TLS 1.2 + HSTS + No Warning + No support for TLS_FALLBACK_SCSV A
TLS 1.2 + HSTS + Warnings + No support for TLS_FALLBACK_SCSV A-

References

  • Modernizing TLS connections in Microsoft Edge and Internet Explorer 11 : https://blogs.windows.com/msedgedev/2018/10/15/modernizing-tls-edge-ie11/
  • Removing Old Versions of TLS : https://blog.mozilla.org/security/2018/10/15/removing-old-versions-of-tls/
  • Deprecation of Legacy TLS 1.0 and 1.1 Versions: https://webkit.org/blog/8462/deprecation-of-legacy-tls-1-0-and-1-1-versions/
  • Modernizing Transport Security: https://security.googleblog.com/2018/10/modernizing-transport-security.html
  • Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS): https://tools.ietf.org/html/rfc7525

1. F5 BIG-IP

BIG-IP ? 系統是一組應用交付產品,它們協同作業以確保高可用性、改進的性能、應用安全和訪問控制,BIG-IP 系統的主要功能之一是將不同型別的協議和應用程式流量定向到適當的目標服務器,系統通過其 Local Traffic Manager? 模塊實作這一點,該模塊可以將流量直接轉發到負載平衡服務器池,或將流量發送到下一跳路由器、路由器池或直接發送到網路上的選定節點,BIG-IP 系統上可用的其他模塊提供關鍵功能,例如將安全策略應用于網路流量、加速 HTTP 連接以及優化廣域網中的連接,

F5 BIG-IP 默認 B 級別(本例基于當前最新的 BIG-IP 16.0.0)

TLS 1.2 + HSTS + No Warning + TLS_FALLBACK_SCSV = A+

(No Warning 即受信任 SSL 證書,TLS_FALLBACK_SCSV F5 默認支持)

故:A 級別 + 開啟 HSTS = A+,推薦啟用 TLSv1_3 和 HTTP/2

其他應用交付產品可以參照 F5 配置

1.1 Ciphers 配置:A 級別 (TLSv1.2)

根據 2020 年 1 月演算法變更,需要 TLSv1.2 及以上版本才能獲得 A,新的 A 級別如下:

ECDHE+AES-GCM:ECDHE+AES-GCM:ECDHE+AES:ECDHE+3DES:RSA+AES-GCM:RSA+AES:RSA+3DES:-MD5:-RC4:-SSLv3:-TLSv1:-TLSv1_1

或者:

ECDHE+AES-GCM:ECDHE+AES:ECDHE+3DES:RSA+AES-GCM:RSA+AES:RSA+3DES:-MD5:-RC4:-SSLv3:-TLSv1:-TLSv1_1

F5 Cipher TLS 版本寫法(與 nginx 和 apache 等使用 OpenSSL 的軟體略有不同):

TLSv1
TLSv1_1
TLSv1_2
TLSv1_3

執行步驟:

編輯 SSL Profile,修改 Ciphers,將默認 Default 替換上述內容,

1.2 啟用 HSTS

HSTS(HTTP Strict Transport Security,RFC6797),即 HTTP 嚴格安全傳輸,是國際互聯網工程組織 IETF 正在推行一種新的 Web 安全協議,網站采用 HSTS 后,用戶訪問時無需手動在地址欄中輸入 HTTPS,瀏覽器會自動采用 HTTPS 訪問網站地址,從而保證用戶始終訪問到網站的加密鏈接,保護資料傳輸安全,HSTS 的作用是強制客戶端(如瀏覽器)使用 HTTPS 與服務器創建連接,服務器開啟 HSTS 的方法是,當客戶端通過 HTTPS 發出請求時,在服務器回傳的超文本傳輸協議回應頭中包含 Strict-Transport-Security 欄位,

Preload List:讓防御更加徹底

HSTS 存在一個比較薄弱的環節,那就是瀏覽器沒有當前網站的 HSTS 資訊的時候,或者第一次訪問網站的時候,依然需要一次明文的 HTTP 請求和重定向才能切換到 HTTPS,以及重繪 HSTS 資訊,而就是這么一瞬間卻給攻擊者留下了可乘之機,使得他們可以把這一次的 HTTP 請求劫持下來,繼續中間人攻擊,針對這種攻擊,HSTS 也有應對辦法,那就是在瀏覽器里內置一個串列 Preload List,只要是在這個串列里的域名,無論何時、何種情況,瀏覽器都只使用 HTTPS 發起連接,這個串列由 Google Chromium 維護,FireFox、Safari、IE 等主流瀏覽器均在使用,

可以通過官網(https://hstspreload.org),查詢網站是否在 Preload List,可以申請將網站加入到 Preload List

執行步驟:

v12 及以上版本直接在 TMUI 中 Enabling HSTS in the HTTP profile 或者使用 iRuels

v11 及以下可以只能通過 iRules 實作

### iRule for HSTS HTTP Virtuals ###
when HTTP_REQUEST {
HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
}
### iRule for HSTS HTTPS Virtuals ###

## 31536000 sec = 1 Year

when HTTP_RESPONSE {
 HTTP::header insert Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}

OR

when HTTP_RESPONSE {
 HTTP::header insert Strict-Transport-Security "max-age=31536000; includeSubDomains"
}

其中:

  • max-age 是必選引數,是一個以秒為單位的數值,它代表著 HSTS Header 的過期時間,通常設定為 1 年,即 31536000 秒,
  • includeSubDomains 是可選引數,如果包含它,則意味著當前域名及其子域名均開啟 HSTS 保護,
  • preload 是可選引數,只有當你申請將自己的域名加入到瀏覽器內置串列的時候才需要使用到它,

1.3 啟用 TLSv1_3

F5 BIG-IP 當前 LTS 版本 14.1.0、15.1.0、16.1.0 及以上版本都可以完整支持 TLSv1_3,

BIG-IP v14 開始支持 TLSv1_3(In BIG-IP 14.0.0, the BIG-IP system adds limited support for Transport Layer Security (TLS) 1.3. Starting in BIG-IP 14.1.0.1 and later, this support was updated to provide production level support for TLS 1.3.)

默認沒有啟用:By default, TLS 1.3 is disabled. To enable TLS 1.3, you must remove the No TLSv1.3 option from the Enabled Options list in the Configuration utility for the Client SSL and Server SSL profiles

You can view a list of TLS 1.3 supported ciphers and groups using the following TMOS Shell (tmsh) commands:

  • To view the supported client-side ciphers, use the following command:

    tmsh run util clientssl-ciphers TLSv1_3

  • To view the supported server-side ciphers, use the following command:

    tmsh run util serverssl-ciphers TLSv1_3

配置啟用 TLSv1_3:

編輯 ClientSSL Profle:

Ciphers:選擇 Cipher Group,下拉選擇 f5-secure

Options:Options List...

Enabled Options,

Disable No TLSv1.3

添加,No TLSv1 和 TLSv1.1,保留默認的 “Don't insert empty fragments”

1.4 配置 HTTP/2

不在贅述,詳見 官方檔案,

配置 HTTP/2 就是在啟用 HTTP profile 的 VS 上關聯一個 HTTP/2 profile,核心引數配置任然在原有的 HTTP profile 上,

特殊配置是 SSL profile 要取消勾選 Renegotiation,其他都可以使用默認配置,

1.5 TLS-FALLBACK-SCSV

TLS-FALLBACK-SCSV(TLS Fallback Signaling Cipher Suite Value)是 OpenSSL 的一種阻止協議降級攻擊的特性和機制,F5 BIG-IP,Nginx 和 Apache httpd 的 HTTPS 皆基于 OpenSSL 實作,符合要求的 OpenSSL 版本即可支持,

Poodle and TLS-FALLBACK-SCSV

SSLv3 allows exploiting of the POODLE bug. This is one more major reason to disable this.

Google have proposed an extension to SSL/TLS named TLS FALLBACK SCSV that seeks to prevent forced SSL downgrades. This is automatically enabled if you upgrade OpenSSL to the following versions:

  • OpenSSL 1.0.1 has TLS FALLBACK SCSV in 1.0.1j and higher.
  • OpenSSL 1.0.0 has TLS FALLBACK SCSV in 1.0.0o and higher.
  • OpenSSL 0.9.8 has TLS FALLBACK SCSV in 0.9.8zc and higher.

TLS Fallback Signaling Cipher Suite Value (SCSV) for Preventing Protocol Downgrade Attacks,

2. Microsoft IIS

Windows? Server 的 Internet 資訊服務 (IIS) 是一種靈活、安全且可管理的 Web 服務器,用于托管 Web 上的任何內容,從媒體流到 Web 應用程式,IIS 的可擴展和開放架構已準備好處理最苛刻的任務,

根據規則:TLS 1.2 + HSTS + No Warning + TLS_FALLBACK_SCSV = A+

理論上 Windows & IIS 不支持 TLS_FALLBACK_SCSV,所以無法 A+,但是 開啟 HSTS,并僅啟用 TLS1.2 可以獲得 A+ 得分,這樣就不存在協議降級風險,

Microsoft 的 SSL 基于 Schannel 實作,與 OpenSSL 無關(或稱 Microsoft TLS),

Schannel is a Security Support Provider (SSP) that implements the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) Internet standard authentication protocols.
The Security Support Provider Interface (SSPI) is an API used by Windows systems to perform security-related functions including authentication. The SSPI functions as a common interface to several SSPs, including the Schannel SSP.

2.1 IIS 獲得 A 級別

測驗環境:IIS 10 on Windows Server 2019

執行 ps 腳本 或者使用 IIS Crypto,將獲得 A,這里以 IIS Crypto 為例:

IIS Crypto:點擊 “Best Pratices”,Server Protocols 只勾選 TLS 1.2,Apply 并重啟生效,

IIS Crypto

僅啟用 TLS 1.2 將獲得 A,遠程桌面也可以正常連接,啟用 HSTS 將獲得 A+,

在早期的 Windows 版本中,僅啟用 TLS 1.2 遠程桌面將無法連接,

2.2 HSTS

分位兩種情況,舊版需要安裝 IIS 模塊,新版(Windows Server 2019+)自帶 HSTS 選項,

  • In older versions of IIS (IIS 7.0 to 10.0 R1703) this requirement can only archived the simple way with an installation of HTTP Strict Transport Security IIS Module.

  • Microsoft added native HTTP Strict Transport Security (HSTS) Support to IIS 10.0 Version 1709

IIS 管理器 -- 選擇站點 -- 高級設定 -- HSTS

IIS-HSTS-01

IIS-HSTS-02

2.3 TLSv1.3

2021 年 8 月發布的 Windows Server 2022 正式支持 HTTP/3、QUIC 和 TLS 1.3 相關特性,

在 Windows Server 2022 中的 IIS 新建一個站點將默認啟用 TLS 1.3 以及 QUIC,除非手動勾選禁用,

備注:IIS 10 & Windows Server 2019 以及之前版本無法支持,參看,

2.4 HTTP/2

版本要求:

HTTP2 requires Windows 2016 with IIS 10 or later.

配置方法:

首先配置好 SSL 證書并創建 HTTPS 站點,IIS 10 默認開啟 HTTP/2 協議,所以我們都不要額外去設定(可以禁用,新建站點時或者 "編輯網站" > "系結..." 勾選 "禁用 HTTP/2"),

IIS-HTTP/2

在 Windows Server 2022 中的 IIS 新建一個站點將默認啟用 TLS 1.3 以及 QUIC(HTTP/3),除非手動勾選禁用,

3. Nginx

nginx [engine x] 是一個 HTTP 和反向代理服務器,郵件代理服務器,和一個通用的 TCP/UDP 代理服務器,最初由 Igor Sysoev 撰寫,在許多負載很重的俄羅斯網站上運行了很久,包括 Yandex,Mail.Ru,VK,和 Rambler,根據 Netcraft 的說法,nginx 服務或代理 22.36% 最繁忙的網站 (2021 年 11 月),
以下是一些成功案例:Dropbox,Netflix,Wordpress.com,FastMail.FM,

3.1 Nginx SSL 證書配置方法

官方檔案

server {
    listen       443 ssl;
    server_name  www.example.com;
    ssl_certificate     www.example.com.crt;
    ssl_certificate_key www.example.com.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ...
}

證書檔案使用 PEM 格式,

證書檔案使用相對路徑時,證書檔案要放在主組態檔相同目錄下(默認 /etc/nginx),

更多配置,這篇文章可以參考:Strong SSL Security on nginx

3.2 TLSv1.3

版本支持如下:

  • The TLSv1.1 and TLSv1.2 parameters (1.1.13, 1.0.12) work only when OpenSSL 1.0.1 or higher is used.
  • The TLSv1.3 parameter (1.13.0) works only when OpenSSL 1.1.1 built with TLSv1.3 support is used.

More info on the NGINX documentation

3.3 HTTP/2

版本要求:

openssl 的版本必須在 1.0.2e 及以上,執行以下命令驗證:

openssl version

nginx 的版本必須在 1.9.5 以上,需要添加 --with-http_v2_module 模塊,執行以下命令驗證:

nginx -V

3.4 參考配置

以下配置:啟用 HTTP/2、TLSv1.3、推薦的 Ciphers、HSTS,可以獲得 A+ 得分

server {
    #listen       443 ssl;
    listen       443 ssl http2; # HTTP/2 Enable
    listen       [::]:443 ssl http2; # IPv6
    server_name  www.sysin.org;
    ssl_certificate     www.sysin.org.crt;
    ssl_certificate_key www.sysin.org.key;
    ssl_protocols       TLSv1.2 TLSv1.3; # Requires nginx >= 1.13.0 else use TLSv1.2
    ssl_ciphers         HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!kRSA;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload" always;
    ...
}

    #ssl_protocols       TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    #ssl_ciphers  HIGH:!aNULL:!MD5;  #B
    #ssl_ciphers  HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!kRSA;  #A
    #ssl_ciphers  ALL:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4;  #B
    #ssl_ciphers  ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;  #A (Mozilla Intermediate)

4. Kubernetes ingress-nginx

4.1 概述

默認 TLS 版本和 Ciphers

nginx-ingress 默認僅使用 TLS 1.2 和 1.3,with a secure set of TLS ciphers.

默認 cipher 串列: ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384.

Legacy TLS 支持

如果需要兼容一些老舊的瀏覽器和作業系統,需要使用 ConfigMap 修改默認配置,例如:

mozilla-ssl-config-old

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
data:
  ssl-ciphers: "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
  ssl-protocols: "TLSv1 TLSv1.1 TLSv1.2 TLSv1.3"

HSTS 默認啟用

可以在 ConfigMap 中配置引數 hsts: "false" 禁用默認行為

HTTP redirect

對于 TLS 型別的 ingress,控制器默認將 HTTP 請求定向到 HTTPS(308 Permanent Redirect response),

可以在 NGINX config map,中使用 ssl-redirect: "false" 引數全域禁用,或者針對單個 ingress 規則使用 annotation nginx.ingress.kubernetes.io/ssl-redirect: "false" 來禁用,

本例部署的 ingress-nginx 版本為 0.30.0,經過測驗只要使用受信任證書,即可獲得 A+ 得分,

4.2 示例

以下發布 Dashboard 為例,配置受信任 SSL 證書,

查看 Dashboard 已經正常部署(部署 Dashboard 參看其他檔案):

kubectl get po,svc -n kubernetes-dashboard -o wide

部署受信任的 SSL 證書:

# 創建 secret,在 ingress 不能直接使用證書需要轉換為 secret 才能使用
# key 和 cert 都為 PEM 格式,cert 包含證書檔案和證書鏈部分
kubectl create secret tls dashboard-ingress-tls --key dashboard-ingress.key --cert dashboard-ingress.crt -n kubernetes-dashboard
# 查看 secret 內容
kubectl get secret dashboard-ingress-tls -n kubernetes-dashboard -o yaml
# 洗掉命令
kubectl delete secret dashboard-ingress-tls -n kubernetes-dashboard

配置 ingress 轉發檔案

# vi dashboard-ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
  name: kubernetes-dashboard-ingress
  namespace: kubernetes-dashboard #注意修改
spec:
  tls:
  - secretName: dashboard-ingress-tls #上述創建的 secret
  rules:
    - host: k8s.sysin.cn #域名
      http:
 paths:
 - path: /
   backend:
     serviceName: kubernetes-dashboard
     servicePort: 443

host: 對應的域名
path: url 背景關系
backend: 后向轉發到對應的 serviceName: 和 servicePort:

注意,dashboard 默認使用 https 提供服務,ingress 默認 backend-protocol 使用 http,這里發布成功的關鍵是要添加 annotations 引數

  annotations:
    nginx.ingress.kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"

部署:

kubectl apply -f dashboard-ingress.yaml

部署成功后可以通過域名訪問:https://k8s.sysin.cn

5. Apache httpd

Apache HTTP Server 專案致力于開發和維護一個用于現代作業系統的開源 HTTP 服務器,包括 UNIX 和 Windows,該專案的目標是提供一個安全、高效和提供與當前 HTTP 同步的 HTTP 服務的可擴展服務器標準,

Apache HTTP 服務器(“httpd”)于 1995 年推出,自 1995 年以來一直是 Internet 上最受歡迎的 Web 服務器,1996 年 4 月,它在 2020 年 2 月慶祝了它作為一個專案的 25 歲生日,

5.1 基本配置

參看 官網檔案

LoadModule ssl_module modules/mod_ssl.so

Listen 443
<VirtualHost *:443>
    ServerName www.example.com
    SSLEngine on
    SSLCertificateFile "/path/to/www.example.com.cert"
    SSLCertificateKeyFile "/path/to/www.example.com.key"
    SSLCipherSuite HIGH:!aNULL:!MD5
    #SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:!aNULL:!MD5
</VirtualHost>

5.2 HTTP/2

Apache Module mod_http2 Available in version 2.4.17 and later

兩種配置:

HTTP/2 in a VirtualHost context (TLS only)

Protocols h2 http/1.1

Allows HTTP/2 negotiation (h2) via TLS ALPN in a secure <VirtualHost>. HTTP/2 preamble checking (Direct mode, see H2Direct) is disabled by default for h2.

HTTP/2 in a Server context (TLS and cleartext)

Protocols h2 h2c http/1.1

Allows HTTP/2 negotiation (h2) via TLS ALPN for secure <VirtualHost>. Allows HTTP/2 cleartext negotiation (h2c) upgrading from an initial HTTP/1.1 connection or via HTTP/2 preamble checking (Direct mode, see H2Direct).

5.3 HSTS

# Load modules (or use the IfModule)
LoadModule headers_module modules/mod_headers.so

LoadModule rewrite_module modules/mod_rewrite.so

Rewrite HTTP connections and redirect them to HTTPS:

# Redirect HTTP connections to HTTPS

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Now configure the virtual host:

<VirtualHost *:443>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</VirtualHost>

5.4 TLSv1.3

版本要求:

Apache version 2.4.36 or greater. (網上文章傳言 2.4.38 是錯誤的!)

OpenSSL version 1.1.1 or greater.

CentOS 8 和 Ubuntu 20.04 自帶軟體包滿足要求,低版本需要編譯安裝,

[root@c8 ~]# openssl version
OpenSSL 1.1.1c FIPS  28 May 2019

[root@c8 ~]# dnf list httpd
Installed Packages
httpd.x86_64        2.4.37-21.module_el8.2.0+382+15b0afa8        @AppStream
root@u20:~# openssl version
OpenSSL 1.1.1f  31 Mar 2020

root@u20:~# apt list apache2
Listing... Done
apache2/focal 2.4.41-4ubuntu3 amd64

僅啟用 TLS 1.2:

SSLProtocol -all +TLSv1.2

配置項如下所示:

<VirtualHost *:443>
    ServerName www.example.com
    DocumentRoot /var/www/html

    SSLEngine on
    SSLProtocol -all +TLSv1.2
    SSLCertificateFile "/path/to/www.example.com.cert"
    SSLCertificateKeyFile "/path/to/www.example.com.key"
</VirtualHost>

啟用 TLS 1.3 和 1.2:

The Apache version 2.4.36 or higher versions support TLS v1.3. You must upgrade Apache packages before enabled TLS 1.3 in SSL settings.

 SSLProtocol -all +TLSv1.2 +TLSv1.3

配置項如下所示:

<VirtualHost *:443>
    ServerName www.example.com
    DocumentRoot /var/www/html

    SSLEngine on
    SSLProtocol -all +TLSv1.2 +TLSv1.3
    SSLCertificateFile "/path/to/www.example.com.cert"
    SSLCertificateKeyFile "/path/to/www.example.com.key"
</VirtualHost>

記得重啟 Apache 服務才能生效,

5.5 參考配置

# For CentOS
yum install mod_ssl
mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bak

組態檔自動增加 "/etc/httpd/conf.modules.d/00-ssl.conf"

echo '
Listen 443
<VirtualHost *:443>
    Protocols h2 http/1.1
    ServerName sysin.org
    DocumentRoot /var/www/html
    SSLEngine on
    SSLProtocol -all +TLSv1.2 +TLSv1.3
    SSLCertificateFile "/etc/httpd/ssl/sysin.org.pem"
    SSLCertificateKeyFile "/etc/httpd/ssl/sysin.org.key"
    SSLCipherSuite HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!kRSA
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</VirtualHost>
' > /etc/httpd/conf.d/sysin.org.conf

其他 Cipher 參考配置

SSLCipherSuite HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!kRSA  #A
SSLCipherSuite ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384  #A (Mozilla Intermediate)

6. Apache Tomcat

Apache Tomcat? 軟體是 Jakarta Servlet、Jakarta Server Pages、Jakarta Expression Language、Jakarta WebSocket、Jakarta Annotations 和 Jakarta Authentication 規范的開源實作,這些規范是 Jakarta EE 平臺的一部分,Jakarta EE 平臺是 Java EE 平臺的演變,Tomcat 10 及更高版本實作了作為 Jakarta EE 一部分開發的規范,Tomcat 9 及更早版本實作了作為 Java EE 一部分開發的規范,

Tomcat 不使用 OpenSSL,所以不支持 TLS-FALLBACK-SCSV 特性,在 Tomcat 9 最新版默認配置即可獲得 A 得分,開啟 HSTS 也是 A 得分,

6.1 基本配置

打開 conf/server.xml 檔案可以看到默認的 SSL/TLS HTTP/1.1 和 HTTP/2 配置方法如下:

    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
    -->
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
    -->
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

Certificate 引數配置參考

6.2 HTTP/2

版本要求:Tomcat 8.5.0,2016-03-24,開始支持 HTTP/2

配置 HTTP/2:即增加 <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />

根據官方檔案使用 PEM 格式證書測驗失敗,這里使用 PFX 格式,

Tomcat 9 強制要求證書別名設定為 tomcat,您需要使用以下 keytool 命令(這里的證書原來別名是 alias,阿里云申請的免費證書默認別名)轉換證書別名為 tomcat:

keytool -changealias -keystore my-cert.pfx -alias alias -destalias tomcat

    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 443 with HTTP/2
    -->
    <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig protocols="TLSv1.2+TLSv1.3"
                       ciphers="HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!kRSA" >
            <Certificate certificateKeystoreFile="conf/k8s.sysin.cn.pfx"
                         certificateKeystoreType="PKCS12"
                         certificateKeystorePassword="your-pfx-password" />
        </SSLHostConfig>
    </Connector>

    <!-- 默認引數如下:
            hostName= default:`_default_`
            ciphers= default:`HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!kRSA`
            protocols= default:`all`
    -->

ciphers 參看:Ciphers,HowTo SSLCiphers

protocols 寫法:

The names of the protocols to support when communicating with clients. This should be a list of any combination of the following:

    SSLv2Hello
    SSLv3
    TLSv1
    TLSv1.1
    TLSv1.2
    TLSv1.3
    all

串列中的每個標記都可以以加號(“+”)或減號(“-”)為前綴,加號添加協議,減號將其從當前串列中洗掉,該串列是從一個空串列開始構建的,

字符 all 是 SSLv2Hello,TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 的別名,

請注意,只有在使用實作 TLSv1.3 的 JVM 時,JSSE 才支持 TLSv1.3,

請注意,對于基于 OpenSSL 的安全連接器,將忽略 SSLv2Hello,如果為基于 OpenSSL 的安全連接器指定了多個協議,它將始終支持 SSLv2Hello,如果指定了單個協議,它將不支持 SSLv2Hello,

請注意,SSLv2 和 SSLv3 本質上是不安全的,

如果未指定,則將使用 all 的默認值,

6.3 HSTS

Response Header 配置

Enabling HSTS (to include maxAgeSeconds = 31536000, includeSubDomains, and preload) requires two modifications of the Tomcat’s conf/web.xml file:

1). 啟用 HSTS 支持,查找以下部分(通過搜索 “httpHeaderSecurity” 關鍵詞):

<!--
    <filter>
        <filter-name>httpHeaderSecurity</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
        <async-supported>true</async-supported>
    </filter>
-->

替換為(或者新增):

    <filter>
        <filter-name>httpHeaderSecurity</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
            <init-param>
                <param-name>hstsEnabled</param-name>
                <param-value>true</param-value>
            </init-param>
            <init-param>
                <param-name>hstsMaxAgeSeconds</param-name>
                <param-value>31536000</param-value>
            </init-param>
            <init-param>
                <param-name>hstsIncludeSubDomains</param-name>
                <param-value>true</param-value>
            </init-param>
            <init-param>
                <param-name>hstsPreload</param-name>
                <param-value>true</param-value>
            </init-param>
        <async-supported>true</async-supported>
    </filter>

2). 繼續搜索 “httpHeaderSecurity” 關鍵詞,查找如下內容,在 “Built In Filter Mappings” 這一段:

<!--
    <filter-mapping>
        <filter-name>httpHeaderSecurity</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
-->

移除注釋,如下:

    <filter-mapping>
        <filter-name>httpHeaderSecurity</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

6.4 HTTP redirection

編輯 server.xml,將 HTTP 重定向到 HTTPS,這里分別使用 80 和 443 埠,搜索 “Connector” 關鍵詞,查找到如下部分:

    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->

修改為:

    <Connector executor="tomcatThreadPool"
               port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443" />

或者修改這里:

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

修改為:

    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443" />

7. HAProxy

HAProxy 是一種免費、快速且可靠的反向代理,可為基于 TCP 和 HTTP 的應用程式提供高可用性、負載平衡和代理,它特別適用于流量非常高的網站,并為世界上大部分訪問量最大的網站提供支持,多年來,它已成為事實上的標準開源負載均衡器,現在隨大多數主流 Linux 發行版一起提供,并且通常默認部署在云平臺中,由于它不做廣告,我們只知道它在管理員報告時被使用:-)

HAProxy 核心團隊并行維護多個版本,從 1.8 版開始,每年都會發布兩個主要版本,第一個數字通常表示重大更改(配置格式等),但實際上很少更改,第二個數字表示新功能,兩者構成一個分支,這些數字后面會出現一個額外的數字,以指示錯誤修復版本,

偶數的分支稱為 “LTS”(用于 “長期支持”),并且在發布后維護 5 年的區域,在此期間,他們將收到針對發布后發現的錯誤的修復程式,這些分支針對的是尋求極端穩定性并且不想過于頻繁地驗證新版本但仍希望收到修復程式的一般用戶,

奇數分支僅被稱為 “穩定”,它們針對那些喜歡經常升級以從現代功能中受益的高技能用戶,并且在出現問題時也能夠回滾,這些版本的維護期為 12 到 18 個月,

7.1 SSL cipher

Global 引數中關于 SSL 的配置

以下三個引數是定義 front:

  • ssl-default-bind-ciphers
ssl-default-bind-ciphers <ciphers> #適用于 TLSv1.2 及以下版本
  • ssl-default-bind-ciphersuites
ssl-default-bind-ciphersuites <ciphersuites> #OpenSSL 1.1.1 or later,TLSv1.3

同時需要同時支持 TLSv1.2 及以下版本和 TLSv1.3 兩個引數需要同時設定,

  • ssl-default-bind-options

示例:

ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
ssl-default-server-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets

以下對應定義 backend server:

  • ssl-default-server-ciphers

適用于 TLSv1.2 及以下版本

  • ssl-default-server-ciphersuites

適用于 OpenSSL 1.1.1 or later,TLSv1.3

  • ssl-default-server-options

參看官方檔案:Configuring TLS Settings

參考配置:

global
......
    #ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 #for TLSv1.2, Mozilla Intermediate
    ssl-default-bind-ciphers HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!kRSA #for TLSv1.2
    ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 #for TLSv1.3
    ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
    #ssl-default-bind-options prefer-client-ciphers no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets
.....

7.2 HTTP/2

HAProxy 1.8 及以上版本支持 HTTP/2

From the 1.8 announcement:

HAProxy 1.8 now supports HTTP/2 on the client side (in the frontend sections) and can act as a gateway between HTTP/2 clients and your HTTP/1.1 and HTTP/1.0 applications.

HTTP/2 協議已經被迅速采用,HAProxy 1.8 現在在客戶端支持 HTTP/2(在前端部分),并且可以充當 HTTP/2 客戶端與 HTTP/1.1 和 HTTP/1.0 應用程式之間的網關,

要啟用對 HTTP/2 的支持,前端部分的系結行必須配置為 SSL 端點,alpn 必須宣布 h2,如下:

frontend myapp
  bind :443 ssl crt /path/to/cert.crt alpn h2,http/1.1
  mode http

備注:cert.crt 證書采用 PEM 格式,包含私鑰、證書,證書鏈在一個檔案中,

7.3 TLSv1.3

要求:HAProxy 1.8.1 及以上,OpenSSL 1.1.1 及以上,

引數:ssl-default-bind-ciphersuites,參看上述 SSL cipher 部分的描述,

7.4 HSTS

方法如下:

frontend public

......

    http-response add-header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"

......

Rewriting HTTP responses 方法示例

  • add-header

語法:

http-response add-header <name> <fmt> [<condition>]

示例:

http-response add-header X-Via %[env(HOSTNAME)]

  • set-header

相當于覆寫或者替換原有 header

語法:

http-response set-header <name> <fmt> [<condition>]

示例:

http-response set-header Server webserver #hide server header

  • del-header

語法:

http-response del-header <name> [<condition>]

示例:

http-response del-header X-Varnish

  • replace-value

高級替換

語法:

http-response replace-value <name> <match-regex> <replace-fmt> [<condition>]

7.5 Redirecting HTTP Requests

重定向 HTTP 請求到 HTTPS,可以參考以下官方示例:

Examples of traffic redirection:

Append a www. prefix in front of all URLs that do not have it:

acl has_www hdr_beg(host) -i www
http-request redirect code 301 location http://www.%[hdr(host)]%[req.uri] unless has_www

Redirect all HTTP traffic to HTTPS when SSL is handled by haproxy:

acl http      ssl_fc,not
http-request redirect scheme https if http

Send redirects for requests for articles without a '/':

acl missing_slash path_reg ^/article/[^/]*$
http-request redirect code 301 prefix / drop-query append-slash if missing_slash

Move the login URL only to HTTPS:

acl http       ssl_fc,not
acl https      ssl_fc
acl u_login    path_beg   /login
acl u_logout   path_beg   /logout
acl up_userid  urlp_len(userid) gt 0
acl cookie_set hdr_sub(cookie) SEEN=1
http-request redirect scheme https if http  u_login
http-request redirect prefix https://%[req.hdr(Host)] set-cookie SEEN=1 if !cookie_set
http-request redirect prefix https://%[req.hdr(Host)] drop-query if u_login !up_userid
http-request redirect scheme http if https !u_login
http-request redirect location / clear-cookie USERID=       if u_logout

7.6 參考配置

Config files and scripts for HAProxy 1.8 with HTTP/2 and dynamic reconfiguration

An 'haproxy.cfg' with:

  • The ability to switch backends dynamically
  • HTTP/2 support in all browsers
  • Logging to systemd
  • The various www vs non-www, HTTP vs HTTPS combinations redirected to a single HTTPS site.
  • A branded 'sorry' page
  • A separate server that handles blogs and marketing content
  • Support for HTML5 Server Sent Events
  • An A+ on the SSL Labs test

See the full docs at fast EV HTTPS verification provider CertSimple.

##https://github.com/certsimple/haproxy-http2-load-balancing-config/blob/master/haproxy.cfg
global
 # Log to systemd's /dev/log compatibility socket
 log /dev/log local0 info

 chroot /var/lib/haproxy
 pidfile /var/run/haproxy.pid
 maxconn 4000
 user haproxy
 group haproxy
 daemon

 # turn on stats unix socket - see http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#3.1-stats%20socket
 stats socket /var/lib/haproxy/stats mode 600 level admin
 stats timeout 2m

 # generated 2020-09-12, Mozilla Guideline v5.6, HAProxy 2.1, OpenSSL 1.1.1d, intermediate configuration
 # https://ssl-config.mozilla.org/#server=haproxy&version=2.1&config=intermediate&openssl=1.1.1d&guideline=5.6
    # intermediate configuration
    ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
    ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
    ssl-default-bind-options prefer-client-ciphers no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets
    #ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets

    ssl-default-server-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
    ssl-default-server-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
    ssl-default-server-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets

    # curl https://ssl-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
    ssl-dh-param-file /path/to/dhparam

defaults
 mode http

 # Needed for GeoIP
 # Enable insertion of the X-Forwarded-For header to requests sent to servers
 # May be used in sections :defaults frontend listen backend
 # http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#4.2-option%20forwardfor
 option forwardfor

 # See http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#option%20http-server-close
 option http-server-close

 log global
 option httplog
 option dontlognull
 option http-server-close
 option forwardfor except 127.0.0.0/8
 option redispatch
 retries 3
 timeout http-request 10s
 timeout queue 1m
 timeout client 1m
 timeout server 1m

 timeout check 10s
 maxconn 3000

 # From http://stackoverflow.com/questions/21419859/configuring-haproxy-to-work-with-server-sent-events
 # Set the max time to wait for a connection attempt to a server to succeed
 timeout connect 30s
 # handle a client suddenly disappearing from the net
 timeout client-fin 30s
 option http-server-close

 # The 'stats' site, where we see what's up and what's down - uncomment and set a password if you want it!
 # stats enable
 # stats uri /haproxy?stats
 # stats realm Strictly\ Private
 # stats auth someusername:i-am-an-awful-password-and-you-should-change-me

 # Show a custom page during site maintenance (ie, when 'blue' and 'green' are both down)
 errorfile 503 /etc/haproxy/errors/503-mycustom.http

frontend public
 # HTTP/2 - see https://www.haproxy.com/blog/whats-new-haproxy-1-8/
 # h2 is HTTP2 with TLS - see https://http2.github.io/faq/
 # Order matters, so h2 before http1.1
 bind :443 ssl crt /etc/https/cert-and-private-key-and-intermediate-and-dhparam.pem alpn h2,http/1.1

 # Redirect http -> https
 bind :80
 redirect scheme https code 301 if ! {ssl_fc}

 # Redirect www -> example.com
 redirect prefix https://example.com code 301 if {hdr(host) -i www.example.com }

 # HSTS (15768000 seconds = 6 months)
 # HSTS (31536000 seconds = 1 years)
 http-response set-header Strict-Transport-Security max-age=31536000

 # Use the marketing site for marketing URLs
 acl marketing path_beg -i /help /sitemap.xml /BingSiteAuth.xml /about /blog /videos/blog /images/blog /fonts/blog /css/blog /js/blog
 use_backend marketing if marketing

 # Everything else goes to the app servers
 default_backend app
 option httpclose
 option forwardfor

backend marketing
 balance roundrobin
 server static 127.0.0.1:8000 check

backend app
 # From http://blog.haproxy.com/2014/01/17/emulating-activepassing-application-clustering-with-haproxy/
 # See also https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#stick-table
 stick-table type ip size 1m
 stick on dst
 # See https://cloud.digitalocean.com/droplets for these IPs
 server green 10.1.1.1:8000 check
 server blue 10.1.1.2:8000 check backup
 # http://stackoverflow.com/questions/21419859/configuring-haproxy-to-work-with-server-sent-events
 timeout tunnel 10h

8. Varnish with Hitch

筆者寫了一篇文章描述了整個配置程序,訪問這里查看:Varnish with Hitch HTTP/2 implement on CentOS 8.0

Varnish Cache 是一種 web 應用程式加速器,同時以被用于快取的 HTTP 反向代理而聞名,Varnish HTTP/2 前端通過 Hitch 代理實作,Hitch 是 Varnish Software 開發的基于 libev 的高性能 SSL/TLS 開源代理軟體,

8.1 啟動 Varnish 支持 HTTP/2

默認情況下,Varnish 中的 HTTP/2 支持是禁用的,因此必須添加一個特性標志才能啟用它,即通過傳遞 “-p feature=+http2” 作為 Varnish 的啟動引數來實作,

您可以通過運行 varnishadm param.show feature 命令來檢查是否已啟用引數,

# varnishadm param.show feature

feature
        Value is: none (default)

        Enable/Disable various minor features.
           none                       Disable all features.

        Use +/- prefix to enable/disable individual feature:
           short_panic                Short panic message.
           wait_silo                  Wait for persistent silo.
           no_coredump                No coredumps.
           esi_ignore_https           Treat HTTPS as HTTP in
                                      ESI:includes
           esi_disable_xml_check      Don't check of body looks like
                                      XML
           esi_ignore_other_elements  Ignore non-esi XML-elements
           esi_remove_bom             Remove UTF-8 BOM
           https_scheme               Also split https URIs
           http2                      Support HTTP/2 protocol
           http_date_postel           Relax parsing of timestamps in
                                      HTTP headers

啟動 Varnish

本例中,Varnish 使用默認配置,事先運行了 Nginx,將 Nginx 默認埠修改為 8080 即可(具體程序略),

varnishd -a :80 -a localhost:6086,PROXY -p feature=+http2 -f /etc/varnish/default.vcl
#或者
varnishd -a localhost:6086,PROXY -p feature=+http2 -f /etc/varnish/default.vcl

驗證 Varnish 已經開啟 HTTP/2 支持

varnishadm param.show feature
feature
        Value is: +http2
        Default is: none

        ......

8.2 hitch 參考配置:Ciphers,HTTP/2 和 TLSv1.3

版本要求:

  • Cache 5.0 開始實驗性的支持 HTTP/2
  • Varnish 6.0 完整支持 HTTP/2
  • hitch 1.5 版本開始支持 TLS 1.3

示例配置(更多引數參看官方檔案):

mv /etc/hitch/hitch.conf /etc/hitch/hitch.conf.bak

echo '
# Run 'man hitch.conf' for a description of all options.

frontend = {
    host = "*"
    port = "443"
}
backend = "[127.0.0.1]:6086"    # 6086 is the default Varnish PROXY port.
workers = 4                     # number of CPU cores

daemon = on

# We strongly recommend you create a separate non-privileged hitch
# user and group
user = "hitch"
group = "hitch"

# Enable to let clients negotiate HTTP/2 with ALPN. (default off)
# Varnish 啟動引數必須增加 `-p feature=+http2`,開啟 HTTP/2 特性(默認關閉)
alpn-protos = "h2, http/1.1"

# run Varnish as backend over PROXY; varnishd -a :80 -a localhost:6086,PROXY ..
write-proxy-v2 = on             # Write PROXY header

syslog = on
log-level = 1

# Add pem files to this directory
#pem-dir = "/etc/pki/tls/private"

## PEM 檔案包含 key、cert 和 chain 的組合,可以支持多個 PEM 檔案
## cat example.com.key example.com.crt my-ca-bundle.crt > example.com.pem
pem-file = "/etc/hitch/varnish.pem"
# 定義第二個 PEM 檔案
#pem-file = "/etc/hitch/mydomain.pem"
## 官方推薦默認 cipher
ciphers = "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"
## Hitch supports TLS (1.0, 1.1, 1.2, 1.3) and SSL 3. By default
tls-protos = TLSv1.2 TLSv1.3
## TCP Fast Open saves up to one full round-trip time (RTT) over the standard three-way connection handshake during a TCP session.
tcp-fastopen = on
' > /etc/hitch/hitch.conf

OCSP staple 相關配置參看 官方檔案

以上配置將獲得 A 評級,加上下面的 HSTS 即可獲得 A+ 評級,

8.3 HSTS

編輯 varnish vcl,如下欄位添加:

sub vcl_deliver {
 set resp.http.Strict-Transport-Security = "max-age=31536000; includeSubDomains; preload";
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/378138.html

標籤:其他

上一篇:TLSv1.3 Support:主流 Web 客戶端和服務端對 TLSv1.3 的支持情況

下一篇:iptables firewall

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more