Setup Cloudflare Origin CA SSL & Full (Strict) Mode on Nginx
Step-by-step setup of 15-year Cloudflare Origin CA certificates on Nginx, enabling Full (Strict) SSL encryption, and locking down UFW firewall to Cloudflare IPs.
Goal
Configure end-to-end encrypted HTTPS using free 15-year Cloudflare Origin CA certificates on Nginx, enable Full (Strict) SSL mode in Cloudflare, and lock down the VPS firewall so all public traffic MUST route through Cloudflare edge proxy.
# Save Certificate to /etc/ssl/cloudflare/origin.pem
sudo nano /etc/ssl/cloudflare/origin.pem
# Save Private Key to /etc/ssl/cloudflare/origin.key
sudo nano /etc/ssl/cloudflare/origin.key
# Lock down file permissions
sudo chmod 600 /etc/ssl/cloudflare/origin.key
sudo chmod 644 /etc/ssl/cloudflare/origin.pem
``````nginx
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name example.com www.example.com;
# Cloudflare Origin CA Certificates
ssl_certificate /etc/ssl/cloudflare/origin.pem;
ssl_certificate_key /etc/ssl/cloudflare/origin.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
Reload Nginx:
```bash
sudo nginx -t && sudo systemctl reload nginx
``````bash
# Allow SSH first!
sudo ufw allow 22/tcp
# Allow Cloudflare IPv4 ranges
for ip in $(curl -s https://www.cloudflare.com/ips-v4); do
sudo ufw allow proto tcp from $ip to any port 80,443
done
# Enable firewall
sudo ufw enable
```Deploy WordPress on Ubuntu VPS (LEMP + FastCGI Micro-Cache + SSL)
Host WordPress on Ubuntu VPS using high-performance LEMP stack, MariaDB, PHP 8.3-FPM, Nginx FastCGI micro-caching, and SSL.
JWT Authentication with HTTP-Only Cookies in Next.js
Implement secure stateless authentication using JSON Web Tokens (JWT), HTTP-only cookies, and Next.js middleware protection.