在 Debian 上搭建的 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 环境,提速一般从 系统层、Nginx、PHP、MySQL、缓存、静态资源 几个方面入手。下面按实战优先级给你一份「可操作清单」。
systemctl list-unit-files --type=service | grep enabled
关闭用不到的:
systemctl disable --now xxx
ulimit -n 65535
永久生效:
/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
fallocate -l 2G /swapfile
mkswap /swapfile
swapon /swapfile
worker_processes auto;
worker_connections 10240;
use epoll;
gzip on;
gzip_min_length 1k;
gzip_comp_level 5;
gzip_types text/css text/js application/json application/javascript image/svg+xml;
open_file_cache max=10000 inactive=30s;
open_file_cache_valid 60s;
open_file_cache_min_uses 2;
location ~* \.(jpg|css|js|png)$ {
expires 30d;
access_log off;
}
listen 443 ssl http2;
apt install php8.2-fpm
/etc/php/8.2/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
opcache.enable=1
opcache.memory_consumption=128
opcache.revalidate_freq=60
disable_functions = exec,passthru,shell_exec,system
/etc/mysql/my.cnf
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
query_cache_type = 0
max_connections = 200
apt install mariadb-server
SHOW FULL PROCESSLIST;
apt install redis-server
PHP:
apt install php-redis
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=phpcache:10m;
apt install htop iotop netdata
或:
curl -sL https://github.com/domoticz/linux-dash | bash
✅ PHP 8 + OPcache
✅ Nginx Gzip + HTTP/2
✅ Redis 缓存
✅ MySQL 内存参数
✅ 静态资源缓存
如果你愿意,可以告诉我:
我可以给你 定制一份 LNMP 配置。