系统级更新
定期更新系统软件包,确保基础环境安全:
sudo apt update && sudo apt upgrade -y
Nginx版本更新
sudo apt install nginx # 升级到最新稳定版
sudo apt full-upgrade # 可选:强制升级所有包(谨慎使用)
安全更新
启用安全更新源,定期安装漏洞补丁:
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 8B48AD6246925553
sudo apt update
sudo apt install nginx nginx-common # 仅安装安全更新
配置管理
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
sudo cp -r /etc/nginx/sites-available /etc/nginx/sites-available.bak
worker_processes
(设为CPU核心数)、worker_connections
等参数,启用keepalive_timeout
提升性能。日志与监控
sudo tail -f /var/log/nginx/access.log /var/log/nginx/error.log
top
、htop
监控资源占用,或搭配Prometheus+Grafana实现可视化监控。安全加固
nginx.conf
中添加server_tokens off;
。ufw
)仅开放HTTP/HTTPS端口,禁止IP直接访问敏感路径。X-Frame-Options
、Content-Security-Policy
)。自动化与容灾
sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
sudo systemctl enable --now unattended-upgrades
nginx -t
),确保故障时可快速回滚。参考来源: