在Ubuntu20.04中安装最新版本的Nginx

我在Ubuntu上安装了最新的稳定版Nginx,并记录了备忘录。

请提供以下内容的中文释义:
【参考】

以下是 Nginx 官方网站的步骤(首页 > 下载 > 预编译包相关链接)。

 

前提条件

Ubuntu 20.04(AWS EC2)

步骤

    1. 安装必需的组件

 

    1. $ sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring

获取签名密钥
$ curl https://nginx.org/keys/nginx_signing.key | gpg –dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

确认输出与官方网站提供的示例一致
$ gpg –dry-run –quiet –import –import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
(略)
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key <signing-key@nginx.com>

配置存储库(stable版本),mainline版本的URL不同
$ echo “deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx” \
| sudo tee /etc/apt/sources.list.d/nginx.list

确认nginx.list中的内容
$ cat /etc/apt/sources.list.d/nginx.list
deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu focal nginx

锁定存储库
$ echo -e “Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n” \
| sudo tee /etc/apt/preferences.d/99nginx

更新、版本确认、安装
$ sudo apt update
$ sudo apt info nginx
Package: nginx
Version: 1.20.2-1~focal
(略)
$ sudo apt install nginx

安装成功后会显示以下类似的消息!

----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* https://nginx.org/en/docs/

Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* https://nginx.org/en/support.html

Commercial subscriptions for nginx are available on:
* https://nginx.com/products/

----------------------------------------------------------------------

开启

由于启动命令sudo systemctl start nginx出现错误,所以我先重新启动了Ubuntu,然后再次确认,一切都正常。

$ sudo systemctl start nginx
$ sudo systemctl status nginx
● nginx.service - nginx - high performance web server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-03-16 13:07:49 UTC; 4min 9s ago
       Docs: https://nginx.org/en/docs/
    Process: 456 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
   Main PID: 474 (nginx)
      Tasks: 2 (limit: 1146)
     Memory: 3.0M
     CGroup: /system.slice/nginx.service
             ├─474 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
             └─478 nginx: worker process

Mar 16 13:07:48 ip-10-0-0-172 systemd[1]: Starting nginx - high performance web server...
Mar 16 13:07:49 ip-10-0-0-172 systemd[1]: nginx.service: Can't open PID file /run/nginx.pid (yet?) after start: Operation not permitted
Mar 16 13:07:49 ip-10-0-0-172 systemd[1]: Started nginx - high performance web server.

其他参考

 

以上 = 以上的内容/上述信息

广告
将在 10 秒后关闭
bannerAds