5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ubuntu20.04に最新のNginxをインストール

Last updated at Posted at 2022-03-16

UbuntuにStable版の最新Nginxをインストールしたので備忘録です。

参考

Nginxの公式サイトの手順(トップページ > download > Pre-Built Packages に記載のリンク)そのままです。

前提条件

Ubuntu 20.04 (AWS EC2)

手順

  1. 必要なものをインストール

    $ sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
    
  2. 署名キー取得

    $ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
        | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
    
  3. 公式サイトにあるお手本通りの出力であることを確認

    $ 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>
    
  4. リポジトリを設定(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
    
  5. 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
    
  6. リポジトリのピン止め

    $ echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
        | sudo tee /etc/apt/preferences.d/99nginx
    
  7. 更新、バージョン確認、インストール

    $ 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を再起動してから再確認したらOKだった

$ 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.

その他参考

以上

5
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?