Debian 11.2にNginxをインストールする方法

環境
# cat /etc/debian_version
11.2

nginxのインストール方法
1.システムを更新します

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

2.依存パッケージをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt install curl gnupg2 ca-certificates lsb-release
# sudo apt install curl gnupg2 ca-certificates lsb-release
# sudo apt install curl gnupg2 ca-certificates lsb-release

3.nginxをインストールします

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

4.nginxの自動起動を設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl enable nginx
Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nginx
# sudo systemctl enable nginx Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable nginx
# sudo systemctl enable nginx
Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nginx

5.nginxの状態を確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:>
Active: active (running) since Sun 2022-03-06 14:05:51 JST; 8s ago
# sudo systemctl status nginx ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:> Active: active (running) since Sun 2022-03-06 14:05:51 JST; 8s ago
# sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:>
Active: active (running) since Sun 2022-03-06 14:05:51 JST; 8s ago

nginx開始
#sudo systemctl start nginx
nginx 停止
#sudo systemctl stop nginx
ngixn 再起動
#sudo systemctl restart nginx

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

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

7.nginxの配置ファイルを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

8.ファイアウォールを設定します
設定済みアプリケーションのファイアウォール一覧を確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo ufw app list
# sudo ufw app list
# sudo ufw app list

nginxのファイアウォールを開放します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo ufw allow 'Nginx HTTP'
Rule added
# sudo ufw allow 'Nginx HTTP' Rule added
# sudo ufw allow 'Nginx HTTP'
Rule added

ファイアウォールのステータスを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo ufw status
Status: active
To Action From
-- ------ ----
19999 ALLOW Anywhere
19999/tcp ALLOW Anywhere
22/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
# sudo ufw status Status: active To Action From -- ------ ---- 19999 ALLOW Anywhere 19999/tcp ALLOW Anywhere 22/tcp ALLOW Anywhere 80/tcp ALLOW Anywhere Nginx HTTP ALLOW Anywhere
# sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
19999                      ALLOW       Anywhere
19999/tcp                  ALLOW       Anywhere
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
Nginx HTTP                 ALLOW       Anywhere

 

Debian 11

Posted by arkgame