🥝

Nginx のインストールおよび関連コマンド

に公開

公式ダウンロードページ

Nginx のダウンロード

  1. wget を使ってダウンロード
cd /usr/local/src

wget https://nginx.org/download/nginx-1.24.0.tar.gz
  1. 圧縮ファイルを解凍
tar -zxvf nginx-1.24.0.tar.gz
  1. コンパイルとインストール
// Nginx の解凍ディレクトリに移動
cd nginx-1.24.0 

// コンパイル前の設定と依存チェック
./configure

//コンパイル 
make 

//インストール
make install

もしコンパイル時に次のようなエラーが出た場合:

make: *** No rule to make target build’, needed by default’. Stop.

以下のように解決できます:

// 以下の依存パッケージをインストール
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
// 再度 configure(オプション付き)
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
// 再コンパイル
make

  1. Nginx を起動
sudo systemctl start nginx

Nginx のコマンド一覧

  • インストール済みか確認
which nginx 
  • バージョン確認
nginx -v
  • Nginx プロセスを確認
ps aux | grep nginx
  • サービスを起動
sudo systemctl start nginx
  • 起動状態を確認
sudo systemctl status nginx
  • Nginx を停止
sudo systemctl stop nginx
  • Nginx を再起動
sudo systemctl restart nginx
  • 設定を再読み込み(サービスを中断せずに)
sudo systemctl reload nginx

Discussion