1、为Nginx创建存储库源文件

sudo nano /etc/apt/sources.list.d/nginx.list
增加两行
deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu/ bionic nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ bionic nginx

Ubuntu 19.04
deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu/ disco nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ disco nginx

2、导入Nginx公钥

wget http://nginx.org/keys/nginx_signing.key

sudo apt-key add nginx_signing.key

3、命令更新存储库信息

sudo apt update
如果您已经从默认的Ubuntu软件存储库中安装了Nginx,则需要将其删除
sudo apt remove nginx nginx-common nginx-full nginx-core
备份主要的Nginx配置
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

4、从nginx.org存储库安装Nginx

sudo apt install nginx
安装Nginx之后,测试Nginx配置
sudo nginx -t
如果测试成功,启动Nginx
sudo systemctl start nginx
启动系统时自动启动
sudo systemctl enable nginx

5、其他

检查Nginx的状态
systemctl status nginx
检查Nginx版本
nginx -v
查看更多详细信息
nginx -V

本文来自:https://www.linuxbabe.com/ubuntu/install-nginx-latest-version-ubuntu-18-04

如果觉得我的文章对你有用,请随意赞赏