AlmaLinux 9.0にWebサーバnginxをインストールする

環境
OSバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cat /etc/redhat-release
AlmaLinux release 9.0 (Emerald Puma)
# cat /etc/redhat-release AlmaLinux release 9.0 (Emerald Puma)
# cat /etc/redhat-release
AlmaLinux release 9.0 (Emerald Puma)

nginxのインストール手順
1.システムパッケージを更新します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo dnf upgrade --refresh -y
# sudo dnf upgrade --refresh -y
# sudo dnf upgrade --refresh -y

2.nginxリポジトリを作成、インストール
dnf-ユーティリティ パッケージをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo dnf install dnf-utils -y
# sudo dnf install dnf-utils -y
# sudo dnf install dnf-utils -y

リポジトリの内容を指定します
# sudo nano /etc/yum.repos.d/nginx.repo
以下の内容を追加します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

3.nginxのインストール
nginxメインラインリポジトリを指定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo yum-config-manager --enable nginx-mainline
# sudo yum-config-manager --enable nginx-mainline
# sudo yum-config-manager --enable nginx-mainline

nginxをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo dnf install nginx -y
# sudo dnf install nginx -y
# sudo dnf install nginx -y

4.nginxバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# nginx -v
nginx version: nginx/1.22.0
# nginx -v nginx version: nginx/1.22.0
# nginx -v
nginx version: nginx/1.22.0

5.ファイアウォールを設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo firewall-cmd --permanent --zone=public --add-service=http
success
# sudo firewall-cmd --permanent --zone=public --add-service=http success
# sudo firewall-cmd --permanent --zone=public --add-service=http
success

httpsの場合、httpsサービス許可を行います

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo firewall-cmd --permanent --zone=public --add-service=https
success
# sudo firewall-cmd --permanent --zone=public --add-service=https success
# sudo firewall-cmd --permanent --zone=public --add-service=https
success

ファイアウォールを再起動します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo firewall-cmd --reload
success
# sudo firewall-cmd --reload success
# sudo firewall-cmd --reload
success

6.nginx起動、停止

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl start nginx
# sudo systemctl start nginx
# sudo systemctl start nginx

自動起動を設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
# sudo systemctl enable nginx Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
# sudo systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

ステータスを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-06-08 11:57:41 JST; 44s ago
# sudo systemctl status nginx ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2022-06-08 11:57:41 JST; 44s ago
# sudo systemctl status nginx
● nginx.service - nginx - high performance web server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
     Active: active (running) since Wed 2022-06-08 11:57:41 JST; 44s ago

7.動作確認
http://プライベートIP or localhost:80にアクセスします
「Welcome to nginx」という画面が表示されます。

AlmaLinux

Posted by arkgame