■目的
後にPacemakerでサーバ2台による冗長化を行いたいので、その前準備として今回は、CentOSにNginxをインストールします。
■環境
・CentOS Stream9
■手順
0.rootユーザになる(rootユーザになっていない場合のみ本手順を実施する。)
# sudo su -
1.Nginxのインストール
# yum -y install nginx
⇒「完了しました!」と表示されること
バージョン確認をしておきます。
# nginx -v
nginx version: nginx/1.20.1
無事インストール出来ました。
2.Nginxのステータス確認
# systemctl status nginx
○ nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; preset: d>
Active: inactive (dead)
事前情報通り、Nginxはインストールしただけで自動起動しないようです。
3.Nginxの起動
以下のコマンドを入力し、Nginxを起動します。
# systemctl start nginx
⇒エラーとならないこと
Nginxが起動したかを項番2.のコマンドを実行し確かめます。
# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; preset: d>
Active: active (running) since Sun 2025-01-26 19:58:41 JST; 2min 26s ago
Process: 11068 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, sta>
Process: 11069 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCE>
Process: 11070 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 11071 (nginx)
Tasks: 2 (limit: 23124)
Memory: 2.0M
CPU: 50ms
CGroup: /system.slice/nginx.service
tq11071 "nginx: master process /usr/sbin/nginx"
mq11072 "nginx: worker process"
⇒「Active: active (running) 」と表示されたこと
4.Nginxの自動起動
毎回、サーバ起動後にNginxを起動させるのが面倒なので、自動起動設定をしておきます。
# systemctl enable nginx
⇒「/usr/lib/systemd/system/nginx.service; enabled」と表示されたこと
5.Nginxのポート開放
Nginxで使用される80番ポートを開放します。
# firewall-cmd --add-port=80/tcp --zone=public --permanent
⇒「success」と表示されたこと
設定をリロードします。
# firewall-cmd --reload
⇒「success」と表示されたこと
設定が反映されたかを確認します。
# firewall-cmd --list-all
"public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:
services: cockpit dhcpv6-client http ssh
ports:
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:"
⇒ services:欄に「http」が反映されたこと
■WEBページ
NICのIPを確認し、WEBページが表示されることを確認します。
# ip a
↑のコマンドでこのサーバのNICのIPが「192.168.56.101」と判明したので、
IPをWEBブラウザに入力します。
⇒テストページが表示されたこと
■参考URL