安装
对于 Nginx 安装,我们使用官方的 Nginx DEB 源。
安装必要的软件
apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
添加官方 Nginx PGP 密钥
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
将Nginx官方源码配置写入nginx.list
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
设置Nginx官方源的优先级高于系统内置源
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
然后更新APT缓存
apt update
安装 Nginx
apt install nginx
最后启动Nginx服务并设置开机启动。
systemctl start nginx
systemctl enable nginx