UbuntuでNginxを起動・停止する方法【XSERVER VPS】

UbuntuにNginxをインストールした後は、Nginxが起動されている状態です。

システムの稼働状態は、systemctl statusコマンドで確認が行えます。

systemctl status nginx

systemctl statusコマンドを実行した際のメッセージを確認すると、Active欄がactive (running)となっていることが確認できます。

# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: en>
     Active: active (running) since Wed 2025-07-09 06:27:28 JST; 32min ago
 Invocation: d5e0978dc084441da319fe39dc0603c7
       Docs: man:nginx(8)
    Process: 43735 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_proc>
    Process: 43736 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (>
   Main PID: 43770 (nginx)
      Tasks: 4 (limit: 2262)
     Memory: 3.6M (peak: 8.8M)
        CPU: 53ms
     CGroup: /system.slice/nginx.service
             ├─43770 "nginx: master process /usr/sbin/nginx -g daemon on; maste>
             ├─43772 "nginx: worker process"
             ├─43773 "nginx: worker process"
             └─43774 "nginx: worker process"

 7月 09 06:27:28 x210-131-210-183 systemd[1]: Starting nginx.service - A high p>
 7月 09 06:27:28 x210-131-210-183 systemd[1]: Started nginx.service - A high pe>
root@x210-131-210-183:~# 

システムを停止するには、systemctl stopコマンドを実行します。

systemctl stop nginx

systemctl statusコマンドを実行した際のメッセージを確認すると、Active欄がinactive (dead)となっていることが確認できます。

# systemctl status nginx
○ nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: en>
     Active: inactive (dead) since Wed 2025-07-09 07:01:18 JST; 12s ago
   Duration: 33min 49.778s
 Invocation: d5e0978dc084441da319fe39dc0603c7
       Docs: man:nginx(8)
    Process: 43735 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_proc>
    Process: 43736 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (>
    Process: 44277 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT>
   Main PID: 43770 (code=exited, status=0/SUCCESS)
   Mem peak: 8.8M
        CPU: 69ms

 7月 09 06:27:28 x210-131-210-183 systemd[1]: Starting nginx.service - A high p>
 7月 09 06:27:28 x210-131-210-183 systemd[1]: Started nginx.service - A high pe>
 7月 09 07:01:18 x210-131-210-183 systemd[1]: Stopping nginx.service - A high p>
 7月 09 07:01:18 x210-131-210-183 systemd[1]: nginx.service: Deactivated succes>
 7月 09 07:01:18 x210-131-210-183 systemd[1]: Stopped nginx.service - A high pe>
root@x210-131-210-183:~# 

システムを起動するには、systemctl startコマンドを実行します。

systemctl start nginx

systemctl statusコマンドで稼働していることが確認できます。

# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: en>
     Active: active (running) since Wed 2025-07-09 07:02:04 JST; 2s ago
 Invocation: 8afe65a53a514977842c7ca34ec70463
       Docs: man:nginx(8)
    Process: 44285 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_proc>
    Process: 44287 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (>
   Main PID: 44288 (nginx)
      Tasks: 4 (limit: 2262)
     Memory: 3.7M (peak: 3.9M)
        CPU: 41ms
     CGroup: /system.slice/nginx.service
             ├─44288 "nginx: master process /usr/sbin/nginx -g daemon on; maste>
             ├─44289 "nginx: worker process"
             ├─44290 "nginx: worker process"
             └─44291 "nginx: worker process"

 7月 09 07:02:04 x210-131-210-183 systemd[1]: Starting nginx.service - A high p>
 7月 09 07:02:04 x210-131-210-183 systemd[1]: Started nginx.service - A high pe>
目次