ข้อดีของ Cloudflare คลาวด์แฟลร์ คือ มันสามารถทำให้สามารถทำให้เว็บเรา สามารถใช้ https/3 เพื่อลดการส่ง package ของ network ลงจาก http1.1 หรือ http2 โดยที่ไม่ต้อง build nginx เป็นพิเศษ
การตั้งค่าบน Cloudflare
- เปิด Cloudflare Dashboard
- ไปแถบเมนูด้านข้าง > Domain (Zone)
- ไปที่จะทำอย่าง plusmagi.com
- ไปแถบเมนูด้านข้าง > Speed > Settings
- Protocol Optimization
- เปิด HTTP/2 Accelerates your website with HTTP/2 (มีไว้ไม่เสียหาย)
- เปิด HTTP/2 to Origin Enable HTTP/2 requests between Cloudflare’s edge and your origin
- เปิด HTTP/3 (with QUIC) Accelerates HTTP requests by using QUIC, which provides encryption and performance improvements compared to TCP and TLS.
- ไปแถบเมนูด้านข้าง > SSL/TLS > Edge Certificates
- เปิด Always Use HTTPS Redirect all requests with scheme “http” to “https”. This applies to all http requests to the zone.
- ไปแถบเมนูด้านข้าง > SSL/TLS > Overview
- คลิก Configure
- Custom SSL/TLS เลือก Full หรือ Full (strict)
การตั้งค่าที่ Nginx
- ตรวจดูก่อนว่าเป็น Nginx 1.25.0 ขึ้นไป โดยคำสั่ง
nginx -v
- เปิดพอร์ต Firewall: ต้องเปิด UDP 443 (ไม่ใช่แค่ TCP) โดยคำสั่ง
sudo ufw allow 443/udp
sudo ufw reload
- แก้ Nginx configuration โดยปกติจะอยู่ที่ /etc/nginx/sites-enabled
cd /etc/nginx/sites-enabled
- เปิด Nginx configuration
- main site เช่น
sudo nano plusmagi.com.wordpress.conf
- เพิ่ม
listen 443 ssl; # สำหรับ TCP (HTTP/1.1, HTTP/2)
listen 443 quic reuseport; # สำหรับ UDP (HTTP/3) – ใส่ reuseport แค่ที่เดียวในไฟล์แรก
# ส่ง Header บอก Browser ว่า Server นี้รองรับ HTTP/3
add_header Alt-Svc ‘h3=”:443″; ma=86400’;
- site อื่น ๆ เช่น
sudo nano plusmagi.com.prime-sql-siis.conf
- เพิ่ม
listen 443 ssl; # สำหรับ TCP (HTTP/1.1, HTTP/2)
listen 443 quic; # HTTP/3 (ห้ามใส่ reuseport ซ้ำ)
# ส่ง Header บอก Browser ว่า Server นี้รองรับ HTTP/3
add_header Alt-Svc ‘h3=”:443″; ma=86400’;
- test nginx โดยคำสั่ง
sudo nginx -t
- restart nginx
sudo systemctl restart nginx
ทดสอบโดย
- ไปที่เว็บ http3check.net
- ใส่ host name เช่น https://pitt.plusmagi.com
- คลิก CHECK
- ถ้าขึ้นมาว่า
- QUIC is supported
- HTTP/3 is supported
แปลว่า User ทั่วไปเข้าใช้งาน HTTP/3 ได้แล้ว
อ่านเพิ่มเติม