VPS Tutorials
Complete VPS Performance Optimization Guide 2025 - Make Your Website 3-5x Faster
A complete 2025 VPS performance optimization guide. From system tuning and web server configuration to database optimization and CDN acceleration, this step-by-step guide shows you how to make your VPS 3-5x faster. Includes best-practice configurations for Nginx, PHP, MySQL, and Redis, plus how to use performance testing tools. After optimization, homepage load time dropped from 3.2 seconds to 0.9 seconds, and concurrent processing capacity increased by 260%.
Bought a VPS and found your website loads slowly and server response times are long? This article teaches you how to optimize VPS performance from scratch and make your website 3-5x faster.
In 2025, Google's Core Web Vitals have become a key factor in SEO rankings. Data shows:
- When a website takes more than 1.5 seconds to load, the bounce rate can reach as high as 68%
- Keeping LCP (Largest Contentful Paint) within 0.8 seconds reduces bounce rate by 40%
- An optimized VPS is on average 1.5 seconds faster than shared hosting
Optimizing a VPS isn't just about speed. It also:
- Reduces server resource consumption and saves costs
- Improves user experience and increases conversion rates
- Improves SEO rankings and brings in more traffic
Before optimizing, first test the VPS's current performance level. These tools are recommended:
System performance testing:
# Bench.sh - 综合性能测试
wget -qO- bench.sh | bash
# Yet-Another-Bench-Script (YABS)
curl -sL yabs.sh | bash
# UnixBench - CPU 性能基准测试
wget --no-check-certificate https://github.com/teddysun/across/raw/master/unixbench.sh
chmod +x unixbench.sh
./unixbench.sh
Network performance testing:
# Speedtest - 测速工具
curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3 -
# 回程路由追踪
curl https://raw.githubusercontent.com/zhucaidan/mtr_trace/main/mtr_trace.sh | bash
Disk IO testing:
# dd 测试磁盘写入速度
dd if=/dev/zero of=test bs=1M count=1024 oflag=direct
# fio 详细 IO 测试
apt install fio -y
fio --randrepeat=1 --ioengine=libaio --direct=1 --name=test --filename=test --bs=4k --size=4G --readwrite=randrw --rwmixread=75
After testing, focus on these metrics:
| Metric | Excellent | Average | Poor |
|---|---|---|---|
| CPU single-core performance | >1200 | 800-1200 | <800 |
| Disk IO (IOPS) | >5000 | 1000-5000 | <1000 |
| Network latency (mainland China) | <100ms | 100-200ms | >200ms |
| Disk write speed | >500MB/s | 100-500MB/s | <100MB/s |
Linux 5.x+ kernels offer significant improvements in network and IO performance:
# Ubuntu/Debian 升级内核
apt update
apt install linux-generic-hwe-22.04
reboot
# 验证内核版本
uname -r
Edit /etc/sysctl.conf and add the following optimization parameters:
# 网络性能优化
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_fastopen = 3
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
# 文件系统优化
fs.file-max = 2097152
vm.swappiness = 10
vm.vfs_cache_pressure = 50
# 应用设置
sysctl -p
BBR congestion control algorithm: BBR, developed by Google, can improve TCP speed by 5-20%, especially in high-latency network environments.
# 查看所有服务
systemctl list-unit-files --type=service
# 禁用不需要的服务(示例)
systemctl disable snapd
systemctl disable bluetooth
systemctl disable cups
Performance comparison (under the same configuration, handling 10,000 concurrent requests):
| Web Server | Requests/sec | Memory Usage | Recommended Scenario |
|---|---|---|---|
| Nginx | 12000 | Low | Static files, reverse proxy |
| LiteSpeed | 15000 | Medium | WordPress optimization |
| Apache | 4000 | High | Traditional applications, .htaccess |
| Caddy | 10000 | Low | Automatic HTTPS |
Recommended configuration: Nginx
# 安装最新版 Nginx
apt install nginx -y
# 编辑 /etc/nginx/nginx.conf
worker_processes auto;
worker_rlimit_nofile 65535;
events {
worker_connections 65535;
use epoll;
multi_accept on;
}
http {
# 启用 Gzip 压缩
gzip on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
# 启用 Brotli 压缩(比 Gzip 快 20%)
brotli on;
brotli_comp_level 6;
# 开启文件缓存
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
# HTTP/2 支持
http2 on;
}
FastCGI cache (for PHP applications):
# /etc/nginx/conf.d/cache.conf
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
location ~ \.php$ {
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 200 60m;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
add_header X-Cache-Status $upstream_cache_status;
}
}
Static file caching:
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
Edit /etc/mysql/my.cnf:
[mysqld]
# 根据 VPS 内存调整(示例:2GB 内存)
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
# 查询缓存
query_cache_type = 1
query_cache_size = 64M
# 连接优化
max_connections = 100
thread_cache_size = 16
Important: innodb_buffer_pool_size is recommended to be set to 50-70% of total memory.
Redis can cache database query results and reduce MySQL load:
# 安装 Redis
apt install redis-server -y
# 优化 Redis 配置 /etc/redis/redis.conf
maxmemory 256mb
maxmemory-policy allkeys-lru
save ""
PHP 8.3 is 30-40% faster than PHP 7.4:
# Ubuntu 安装 PHP 8.3
apt install software-properties-common -y
add-apt-repository ppa:ondrej/php -y
apt update
apt install php8.3-fpm php8.3-mysql php8.3-redis -y
Edit /etc/php/8.3/fpm/php.ini:
[opcache]
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
Edit /etc/php/8.3/fpm/pool.d/www.conf:
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500
Recommended free CDNs:
- Cloudflare: Global CDN + DDoS protection; the free plan is sufficient
- jsDelivr: Specifically accelerates JS/CSS libraries
# 安装图片优化工具
apt install jpegoptim optipng webp -y
# 批量优化 JPEG
find /var/www/html -name '*.jpg' -exec jpegoptim --max=85 {} \;
# 批量优化 PNG
find /var/www/html -name '*.png' -exec optipng -o5 {} \;
# 转换为 WebP 格式(体积减少 25-35%)
for file in *.jpg; do cwebp -q 85 "$file" -o "${file%.jpg}.webp"; done
# htop - 实时系统监控
apt install htop -y
# iotop - IO 监控
apt install iotop -y
# netdata - 可视化监控面板
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
# 清理系统缓存
apt autoremove -y
apt clean
# 清理日志文件
journalctl --vacuum-time=7d
# 清理 Nginx 缓存
rm -rf /var/cache/nginx/*
nginx -s reload
Real data comparison before and after optimization (2GB memory VPS running WordPress):
| Metric | Before Optimization | After Optimization | Improvement |
|---|---|---|---|
| Homepage load time | 3.2s | 0.9s | 72% |
| TTFB | 850ms | 180ms | 79% |
| Concurrent processing capacity | 50 req/s | 180 req/s | 260% |
| Memory usage | 85% | 45% | 47% |
| CPU idle rate | 15% | 60% | 300% |
Q: How long after optimization will I see results? A: System-level optimizations take effect immediately. CDN and cache configurations take 10-30 minutes to take effect.
Q: Will optimization affect website stability? A: Following the tutorial will not affect stability. It is recommended to verify in a test environment first, then apply to the production environment.
Q: Can small-memory VPSs (512MB-1GB) also be optimized?
A: Yes, but reduce cache sizes appropriately. For 512MB memory, recommended: innodb_buffer_pool_size = 256M, Redis maxmemory = 128mb.
Q: How do I choose the right VPS? A: Prioritize: NVMe disk > SSD > HDD, network bandwidth >100Mbps, and preferably CN2/optimized routes.
VPS performance optimization is an ongoing process. The core points:
- Diagnosis first: Use testing tools to find bottlenecks
- Layered optimization: System → Web server → Database → Application
- Caching is king: Redis + FastCGI + CDN combination
- Regular maintenance: Monitor resource usage and clean up promptly
A well-optimized VPS is not only faster but also saves costs. An optimized 2GB VPS can match the performance of an unoptimized 4GB VPS.
Want to learn more VPS optimization tips? Check out our other articles: