ค้นหาเว็บไซต์

วิธีเปิดใช้งาน TLS 1.3 ใน Apache และ Nginx


TLS 1.3 เป็นเวอร์ชันล่าสุดของโปรโตคอล Transport Layer Security (TLS) และเป็นไปตามข้อกำหนด 1.2 ที่มีอยู่พร้อมกับมาตรฐาน IETF ที่เหมาะสม: RFC 8446 มอบความปลอดภัยที่แข็งแกร่งยิ่งขึ้นและปรับปรุงประสิทธิภาพที่สูงกว่ารุ่นก่อน

ในบทความนี้ เราจะแสดงคำแนะนำทีละขั้นตอนเพื่อรับใบรับรอง TLS ที่ถูกต้อง และเปิดใช้งานโปรโตคอลเวอร์ชัน TLS 1.3 ล่าสุดบนโดเมนของคุณที่โฮสต์บน Apache หรือ เว็บเซิร์ฟเวอร์ Nginx

ความต้องการ:

  • อาปาเช่ เวอร์ชัน 2.4.37 หรือสูงกว่า
  • Nginx เวอร์ชัน 1.13.0 หรือสูงกว่า
  • OpenSSL เวอร์ชัน 1.1.1 หรือสูงกว่า
  • ชื่อโดเมนที่ถูกต้องพร้อมบันทึก DNS ที่กำหนดค่าอย่างถูกต้อง
  • ใบรับรอง TLS ที่ถูกต้อง

ติดตั้งใบรับรอง TLS จาก Let's Encrypt

หากต้องการรับ ใบรับรอง SSL ฟรีจาก Let's Encrypt คุณต้องติดตั้งไคลเอนต์ Acme.sh และแพ็คเกจที่จำเป็นบางส่วนบนระบบ Linux ดังที่แสดง


apt install -y socat git  [On Debian/Ubuntu]
dnf install -y socat git  [On RHEL/CentOS/Fedora]
mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh 
./acme.sh --install --home /etc/letsencrypt --accountemail [email 
cd ~
/etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --ocsp-must-staple --keylength 2048
/etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --ocsp-must-staple --keylength ec-256

หมายเหตุ: แทนที่ example.com ในคำสั่งด้านบนด้วยชื่อโดเมนจริงของคุณ

เมื่อคุณติดตั้งใบรับรอง SSL แล้ว คุณสามารถดำเนินการต่อเพื่อเปิดใช้งาน TLS 1.3 บนโดเมนของคุณตามที่อธิบายไว้ด้านล่าง

เปิดใช้งาน TLS 1.3 บน Nginx

ตามที่ฉันได้กล่าวไว้ในข้อกำหนดข้างต้น TLS 1.3 ได้รับการสนับสนุนตั้งแต่เวอร์ชัน Nginx 1.13 หากคุณใช้ Nginx เวอร์ชันเก่า คุณต้องอัปเกรดเป็นเวอร์ชันล่าสุดก่อน


apt install nginx
yum install nginx

ตรวจสอบเวอร์ชัน Nginx และเวอร์ชัน OpenSSL ที่มีการคอมไพล์ Nginx (ตรวจสอบให้แน่ใจว่าเวอร์ชัน nginx เป็นอย่างน้อย 1.14 และ openssl เวอร์ชัน 1.1.1)


nginx -V
ผลลัพธ์ตัวอย่าง

nginx version: nginx/1.14.1
built by gcc 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC) 
built with OpenSSL 1.1.1 FIPS  11 Sep 2018
TLS SNI support enabled
....

ตอนนี้เริ่มเปิดใช้งานและตรวจสอบการติดตั้ง nginx


systemctl start nginx.service
systemctl enable nginx.service
systemctl status nginx.service

ตอนนี้เปิดไฟล์การกำหนดค่า nginx vhost /etc/nginx/conf.d/example.com.conf โดยใช้โปรแกรมแก้ไขที่คุณชื่นชอบ


vi /etc/nginx/conf.d/example.com.conf

และค้นหาคำสั่ง ssl_protocols และต่อท้าย TLSv1.3 ที่ท้ายบรรทัดดังที่แสดงด้านล่าง


server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  server_name example.com;

  # RSA
  ssl_certificate /etc/letsencrypt/example.com/fullchain.cer;
  ssl_certificate_key /etc/letsencrypt/example.com/example.com.key;
  # ECDSA
  ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.cer;
  ssl_certificate_key /etc/letsencrypt/example.com_ecc/example.com.key;

  ssl_protocols TLSv1.2 TLSv1.3;
  ssl_ciphers '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';
  ssl_prefer_server_ciphers on;
}

สุดท้าย ตรวจสอบการกำหนดค่าและโหลด Nginx อีกครั้ง


nginx -t
systemctl reload nginx.service

เปิดใช้งาน TLS 1.3 ใน Apache

เริ่มต้นจาก Apache 2.4.37 คุณสามารถใช้ประโยชน์จาก TLS 1.3 ได้ หากคุณใช้ Apache เวอร์ชันเก่า คุณจะต้องอัปเกรดเป็นเวอร์ชันล่าสุดก่อน


apt install apache2
yum install httpd

เมื่อติดตั้งแล้ว คุณสามารถตรวจสอบ Apache และเวอร์ชัน OpenSSL ที่ Apache คอมไพล์ได้


httpd -V
openssl version

ตอนนี้เริ่มเปิดใช้งานและตรวจสอบการติดตั้ง nginx


-------------- On Debian/Ubuntu -------------- 
systemctl start apache2.service
systemctl enable apache2.service
systemctl status apache2.service

-------------- On RHEL/CentOS/Fedora --------------
systemctl start httpd.service
systemctl enable httpd.service
systemctl status httpd.service

ตอนนี้เปิดไฟล์การกำหนดค่าโฮสต์เสมือน Apache โดยใช้โปรแกรมแก้ไขที่คุณชื่นชอบ


vi /etc/httpd/conf.d/vhost.conf
OR
vi /etc/apache2/apache2.conf

และค้นหาคำสั่ง ssl_protocols และต่อท้าย TLSv1.3 ที่ท้ายบรรทัดดังที่แสดงด้านล่าง


<VirtualHost *:443>
SSLEngine On

RSA
ssl_certificate /etc/letsencrypt/example.com/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/example.com/example.com.key;
ECDSA
ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/example.com_ecc/example.com.key;

ssl_protocols TLSv1.2 TLSv1.3
ssl_ciphers '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';
ssl_prefer_server_ciphers on;
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem

     ServerAdmin [email 
     ServerName www.example.com
     ServerAlias example.com
    #DocumentRoot /data/httpd/htdocs/example.com/
    DocumentRoot /data/httpd/htdocs/example_hueman/
  # Log file locations
  LogLevel warn
  ErrorLog  /var/log/httpd/example.com/httpserror.log
  CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/example.com/httpsaccess.log.%Y-%m-%d 86400" combined
</VirtualHost>

สุดท้าย ตรวจสอบการกำหนดค่าและโหลด Apache อีกครั้ง


-------------- On Debian/Ubuntu -------------- 
apache2 -t
systemctl reload apache2.service

-------------- On RHEL/CentOS/Fedora --------------
httpd -t
systemctl reload httpd.service

ตรวจสอบว่าไซต์ใช้ TLS 1.3

เมื่อคุณกำหนดค่าผ่านเว็บเซิร์ฟเวอร์แล้ว คุณจะตรวจสอบได้ว่าไซต์ของคุณแฮนด์เชคผ่านโปรโตคอล TLS 1.3 โดยใช้เครื่องมือพัฒนาเบราว์เซอร์ Chrome ในเวอร์ชัน Chrome 70+

นั่นคือทั้งหมดที่ คุณได้เปิดใช้งานโปรโตคอล TLS 1.3 บนโดเมนของคุณที่โฮสต์บนเว็บเซิร์ฟเวอร์ Apache หรือ Nginx สำเร็จแล้ว หากคุณมีข้อสงสัยเกี่ยวกับบทความนี้ โปรดถามในส่วนความคิดเห็นด้านล่าง