ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球
子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール
親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
| この記事の要点 |
|
主要コマンド早見表
| 目的 | コマンド |
|---|---|
| 起動 | sudo systemctl start nginx |
| 停止 | sudo systemctl stop nginx |
| 再起動(プロセス再生成) | sudo systemctl restart nginx |
| 無停止リロード(設定再読込) | sudo systemctl reload nginx |
| 状態確認 | systemctl status nginx |
| 稼働中か(true/false) | systemctl is-active nginx |
| 自動起動有効化 | sudo systemctl enable nginx |
| 自動起動無効化 | sudo systemctl disable nginx |
| 自動起動状態確認 | systemctl is-enabled nginx |
| 設定構文チェック | sudo nginx -t |
| ログ表示(リアルタイム) | sudo journalctl -u nginx -f |
起動・停止・再起動
# 起動
sudo systemctl start nginx
# 停止
sudo systemctl stop nginx
# プロセス完全再起動(短時間切断あり)
sudo systemctl restart nginx
# 設定だけ再読込(無停止、推奨)
sudo systemctl reload nginx
# プロセスが居なければ起動、居れば再起動
sudo systemctl restart nginx
reload と restart の違い
本番運用では原則 reloadを使います。restart は接続が切れます。
| 操作 | 動作 | 切断 | 使い所 |
|---|---|---|---|
| reload | マスタープロセスが新ワーカー起動 → 古いワーカーは処理完了後に終了 | 無し | 設定変更後 |
| restart | マスター含め全プロセス停止 → 起動 | あり(数百 ms) | nginx 自体のアップグレード後 |
必ず構文チェックしてから reload
設定ミスがあると reload は失敗し、最悪はマスターが起動しなくなることもあります。nginx -t で構文チェック後に reload が鉄則。
# 設定ファイル構文チェック
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
# 確認 OK なら reload
sudo systemctl reload nginx
# ワンライナー(チェック失敗なら reload しない)
sudo nginx -t && sudo systemctl reload nginx
自動起動(enable / disable)
# OS 起動時に自動で nginx を立ち上げる
sudo systemctl enable nginx
# 状態確認
systemctl is-enabled nginx
# enabled / disabled / static / masked
# 自動起動無効化
sudo systemctl disable nginx
# enable と start を同時に
sudo systemctl enable --now nginx
# disable と stop を同時に
sudo systemctl disable --now nginx
状態確認の見方
$ systemctl status nginx
* nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2026-06-10 09:00:00 JST; 2h ago ← 稼働状態
Process: 1234 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 1235 (nginx)
Tasks: 5 (limit: 23456)
Memory: 12.3M
CGroup: /system.slice/nginx.service
├─1235 nginx: master process /usr/sbin/nginx
├─1236 nginx: worker process
├─1237 nginx: worker process
├─1238 nginx: worker process
└─1239 nginx: worker process
Jun 10 09:00:00 host systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jun 10 09:00:00 host systemd[1]: Started The nginx HTTP and reverse proxy server.
# 主な Active 状態
# active (running) → 稼働中
# active (exited) → 起動成功して終了(oneshot 型)
# inactive (dead) → 停止
# failed → 異常終了(要調査)
スクリプトで使う系コマンド
# シェルスクリプトの分岐で使いやすい
if systemctl is-active --quiet nginx; then
echo "running"
else
echo "stopped"
sudo systemctl start nginx
fi
# 戻り値で判定
systemctl is-active nginx > /dev/null && echo OK
# 全 unit から nginx 系を絞り込み
systemctl list-units --type=service | grep nginx
ログの確認
# アクセスログ
sudo tail -f /var/log/nginx/access.log
# エラーログ
sudo tail -f /var/log/nginx/error.log
# systemd ジャーナル(起動失敗時はこちらが詳しい)
sudo journalctl -u nginx -f # リアルタイム
sudo journalctl -u nginx --since today
sudo journalctl -u nginx -n 100 # 最新 100 行
sudo journalctl -u nginx -p err # error 以上のみ
# ログのサイズ確認とローテーション
ls -lh /var/log/nginx/
cat /etc/logrotate.d/nginx
ポート / プロセスの確認
# 待ち受けポート
sudo ss -tlnp | grep nginx
# LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=1235,fd=6))
# 旧 netstat(要 net-tools)
sudo netstat -tlnp | grep nginx
# プロセス
ps aux | grep nginx
# nginx: master process /usr/sbin/nginx
# nginx: worker process
ファイアウォール (firewalld) と SELinux
CentOS / RHEL は firewalld と SELinux がデフォルト有効です。nginx を立てたのに外からアクセスできない場合は要確認。
# firewalld で 80/443 を開放
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
# SELinux で nginx が独自ポート (例 8080) を listen する場合
sudo semanage port -a -t http_port_t -p tcp 8080
# SELinux で /var/www 以外を DocumentRoot にする場合
sudo chcon -Rt httpd_sys_content_t /opt/myapp/public/
sudo setsebool -P httpd_can_network_connect on # upstream へ接続許可
# 一時的に SELinux を無効化して切り分け(推奨しない)
sudo setenforce 0
起動失敗時のトラブルシューティング
# 1. status で原因確認
sudo systemctl status nginx -l
# 2. journal の最新エラー
sudo journalctl -u nginx -n 50 --no-pager
# 3. 設定ミス確認
sudo nginx -t
# 4. ポート競合確認(80/443 が既に使われていないか)
sudo ss -tlnp | grep -E ':80|:443'
# Apache が動いていたら停止
sudo systemctl stop httpd
sudo systemctl disable httpd
# 5. ファイル権限確認
ls -la /var/log/nginx/
ls -la /etc/nginx/nginx.conf
古い CentOS 6 系(systemd 以前)
CentOS 6 以前は init.d / chkconfig を使います。CentOS 7 以降は systemd 統一。
# CentOS 6 (init.d)
sudo service nginx start
sudo service nginx stop
sudo service nginx restart
sudo service nginx reload
sudo service nginx status
# 自動起動
sudo chkconfig nginx on
sudo chkconfig nginx off
chkconfig --list nginx
FAQ
Q: nginx -s reload と systemctl reload nginx の違い
A: ほぼ同じ(マスターに HUP シグナルを送る)。systemctl 経由のほうが状態管理されるので推奨。
Q: reload しても変更が反映されない
A: nginx -T で実際に読み込まれている設定をダンプ。include 関係や server_name のミスを確認。キャッシュ系ディレクティブは reload で反映されないものもあり、その場合は restart 必要。
Q: 起動時に "Failed to read PID"
A: /run/nginx.pid の権限・存在を確認。設定の pid ディレクティブと systemd unit ファイルの PIDFile= 一致を確認。
ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球
子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール
親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
子ページはありません
- インストール (CentOS編)
- 起動・停止コマンドとステータスの確認 (CentOS編)
- VPSへの導入例
- ドキュメントルートの変更方法
- phpを動かす際に必要な設定
- サブドメインの設定方法
人気ページ
- 1 Eclipseで「サーバーに追加または除去できるリソースがありません。」の原因と対処法
- 2 tomcat の起動 / 停止ログと catalina.log・catalina.out の違い
- 3 JavaScript base URL 取得方法|window.location.origin と SSR/Node.js 対応
- 4 YouTube Data API v3 エラー一覧|403/400/404 の主要原因と切り分け
- 5 Spring Frameworkのアノテーション一覧
- 6 Laravel エラー一覧|500/Blade/DB 接続/ルーティングの代表エラー
- 7 3Dグラフィックスとは|モデリング/レンダリング/主要ソフトウェア (Blender / Maya)
- 8 【Spring】@Valueアノテーションとは
- 9 CATALINA_HOME の確認方法 (Linux / Mac)
- 10 【Spring】@Autowiredアノテーションとは
最近更新/作成されたページ
- IPv6とは|128bitアドレス・コロン16進表記/::省略・リンクローカル・SLAAC・デュアルスタック NEW 2026-06-22 12:34:44
- MAC アドレスフィルタリングの仕組みと限界 | ネットワーク入門 NEW 2026-06-22 12:19:10
- VPNとは|暗号トンネル・サイト間/リモートアクセス・IPsec/SSL-VPN/WireGuardを解説 NEW 2026-06-22 12:19:10
- WebSocket とは 全二重リアルタイム通信 ws/wss | ネットワーク入門 NEW 2026-06-22 12:17:25
- HTTP/2 とは 多重化・HPACK・バイナリフレーム | ネットワーク入門 NEW 2026-06-22 12:17:25
- Web通信プロトコル入門 HTTP/2・HTTP/3・WebSocket・gRPC・WebRTC | ネットワーク入門 NEW 2026-06-22 12:17:25
- gRPC とは HTTP/2 + Protocol Buffers の高速 RPC | ネットワーク入門 NEW 2026-06-22 12:17:25
- HTTP/3 (QUIC) とは UDP ベースの低遅延 Web 通信 | ネットワーク入門 NEW 2026-06-22 12:17:25
- WebRTC とは ブラウザ間 P2P の音声・映像・データ通信 | ネットワーク入門 NEW 2026-06-22 12:17:25
- 証明書と認証局(CA)とは|X.509・信頼チェーン・DV/OV/EV・失効(CRL/OCSP)を解説 NEW 2026-06-22 12:17:24
- ファイアウォールとは|パケットフィルタ・ステートフル・DMZ・次世代FW(L4/L7)を解説 NEW 2026-06-22 12:17:24
- iptables/nftablesとは|テーブル・チェーン・ルール例・永続化をLinux視点で解説 NEW 2026-06-22 12:17:24
- HAProxy とは frontend/backend と設定例 | ネットワーク入門 NEW 2026-06-22 12:17:24
- TLS/SSLの仕組み|ハンドシェイク・暗号スイート・前方秘匿性・証明書検証をわかりやすく解説 NEW 2026-06-22 12:17:24
- CDN とは エッジキャッシュ・TTL・Cloudflare/CloudFront | ネットワーク入門 NEW 2026-06-22 12:17:24
コメントを削除してもよろしいでしょうか?