FastCGI Caching with Nginx for WordPress is a common requirement for VPS administrators. This guide provides practical instructions that you can follow on Ubuntu 22.04/24.04 or Debian 12, though most steps apply to other distributions as well.
Prerequisites
- A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
- A registered domain name (for public-facing services)
- Basic familiarity with the Linux command line
Baseline Measurement
Security should be a primary consideration when configuring fastcgi. Always use strong passwords, keep software updated, and restrict network access to only the necessary ports and IP addresses.
# Kernel tuning: /etc/sysctl.d/99-performance.conf
cat << 'EOF' | sudo tee /etc/sysctl.d/99-performance.conf
# Network performance
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15
# Memory management
vm.swappiness = 10
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5
# File descriptors
fs.file-max = 2097152
fs.nr_open = 2097152
EOF
sudo sysctl --system
These commands should be run as root or with sudo privileges. If you're using a non-root user, prefix each command with sudo.
- Use SSH keys instead of password authentication
- Set up fail2ban for brute force protection
- Enable firewall and allow only necessary ports
- Use strong, unique passwords for all services
- Keep all software components up to date
Kernel and OS Tuning
The nginx component plays a crucial role in the overall architecture. Understanding how it interacts with fastcgi will help you make better configuration decisions.
# Benchmark before and after optimization
# CPU benchmark
sysbench cpu --cpu-max-prime=20000 run
# Memory benchmark
sysbench memory --memory-block-size=1M --memory-total-size=10G run
# Disk I/O benchmark
sysbench fileio --file-total-size=4G --file-test-mode=rndrw prepare
sysbench fileio --file-total-size=4G --file-test-mode=rndrw run
sysbench fileio --file-total-size=4G cleanup
The output should show the service running without errors. If you see any warning messages, address them before proceeding to the next step.
Performance Considerations
When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.
Wrapping Up
Following this guide, your fastcgi setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.