確保Debian LNMP(Linux, Nginx, MySQL/MariaDB, PHP)環境的穩定性是非常重要的。以下是一些關鍵步驟和建議,可以幫助你維護一個穩定且高效的LNMP環境:
apt
包管理器定期更新系統及其軟件包。sudo apt update && sudo apt upgrade -y
sudo apt install unattended-upgrades
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
add_header Cache-Control "public";
}
upstream backend {
server backend1.example.com;
server backend2.example.com;
}
server {
location / {
proxy_pass http://backend;
}
}
/etc/mysql/my.cnf
或/etc/mysql/mariadb.conf.d/50-server.cnf
)。
mysqldump
或其他備份工具定期備份數據庫。mysqldump -u username -p database_name > backup.sql
slow_query_log = 1
long_query_time = 2
log_error = /var/log/mysql/error.log
/etc/php/7.x/fpm/pool.d/www.conf
)。
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
htop
、nmon
、glances
等監控系統資源使用情況。ufw
或其他防火墻工具限制不必要的網絡訪問。sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com
sudo apt clean
sudo rm -rf /var/log/nginx/*
smartctl
檢查硬盤健康狀況。通過以上步驟,你可以大大提高Debian LNMP環境的穩定性和性能。記得定期檢查和調整配置,以適應不斷變化的需求和環境。