作記録

記憶代わり

【Nginx】Nginxを起動する手順

本記事より下記の記事の方が分かりやすいかも jtnsaku.hatenablog.com

以下、一応本記事

Nginxを起動する手順

AWSのEC2により、Amazon Linux2 OS上での操作を想定しています。

Nginxをビルドする為に必要なライブラリをインストールする。

GCC
Cコンパイラ
sudo yum -y install gcc
バージョン: gcc-7.3.1-9.amzn2.x86_64

PCRE
正規表現の処理をする。
sudo yum -y install pcre-devel
バージョン: pcre-devel-8.32-17.amzn2.0.2.x86_64

zlib
データの圧縮、伸縮などの処理をする。
sudo yum -y install zlib-devel
バージョン: zlib-devel-1.2.7-18.amzn2.x86_64

OpenSSL
SSL/TLSプロトコルの処理をする。
sudo yum -y install openssl-devel
バージョン: openssl-devel-1.0.2k-19.amzn2.0.3.x86_64

Nginxをインストールする。

①Nginxの圧縮データをダウンロードする。
wget http://nginx.org/download/nginx-1.19.3.tar.gz
バージョン: nginx-1.19.3

②上記①でダウンロードしたnginxの圧縮データを解凍する。
tar xvf nginx-1.19.3.tar.gz

Nginxをビルドする。

①上記「Nginxをインストールする」の②で解凍したnginx-1.19.3ディレクトリ内にconfigure実行ファイルがあるので、チェンジする。
cd nginx-1.19.3

②Nginxを起動する際の設定を書き込む。
./configure [引数]
例: ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx
引数に指定できるパラメータは、Nginxの公式ドキュメントに記載がある。
上記でインストールしたいくつかのライブラリは、この./configureで利用する。
特に指定しないと下記のようにデフォルトの設定が適用される。

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

④下記のコマンドを実行する。
make
sudo make install

Nginxを起動する。

sudo nginx

nginx.confの位置

上記の「Nginxをビルドする。」の③で .configure --conf-path=[nginx.confへのパス]で指定した箇所にnginx.confを置く。
なお、デフォルトでは上記で表示の通り /usr/local/nginx/conf/nginx.conf に置く。

参考文献

著: 久保 達彦、道井 俊介 『nginx 実践入門』技術評論社