Rocky Linux9 nginxをインストールする

Rocky Linux9 nginxをインストールする

Rocky Linux9に、webサーバーであるnginxをインストールする手順を記述してます。

環境

  • OS  Rocky Linux release 9.0 (Blue Onyx)

nginxインストール

先に、アップデートしておきます。

$ sudo dnf update

「dnf」で、インストールします。

$ sudo dnf -y install nginx

バージョンが確認できればインストール完了です。

$ nginx -version

nginx version: nginx/1.20.1

nginx起動

nginxを起動します。

$ sudo systemctl start nginx

自動起動も設定する場合は、以下となります。

$ sudo systemctl enable --now nginx

ステータスは、以下で確認できます。

$ sudo systemctl status nginx

● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
     Active: active (running) since Sat 2022-09-10 16:05:10 JST; 5s ago
    Process: 351755 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
    Process: 351756 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
    Process: 351757 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
   Main PID: 351758 (nginx)
      Tasks: 2 (limit: 15463)
     Memory: 2.0M
        CPU: 21ms
     CGroup: /system.slice/nginx.service
             ├─351758 "nginx: master process /usr/sbin/nginx"
             └─351759 "nginx: worker process"

 9月 10 16:05:10 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
 9月 10 16:05:10 localhost.localdomain nginx[351756]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
 9月 10 16:05:10 localhost.localdomain nginx[351756]: nginx: configuration file /etc/nginx/nginx.conf test is successful
 9月 10 16:05:10 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.

firewallを設定していれば、許可しておきます。

$ sudo firewall-cmd --permanent --zone=public --add-service=http 
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --reload

ブラウザから http://プライベートIP or サーバーアドレス にアクセスすると、nginxが起動していることが確認できます。

設定ファイル

設定ファイルは、以下の場所にあります。

/etc/nginx/nginx.conf

公開ドキュメントルート

デフォルトの公開ドキュメントルートは、以下のパスとなります。

/usr/share/nginx/html