ソースコードの取得
安定版 NGINX 本体および必要となるサードパーティモジュールを shallow clone で取得します。
# NGINX コア(v1.14 系安定ブランチ)
git clone https://github.com/nginx/nginx.git --depth 1 -b branches/stable-1.14 nginx-core
# サーバー健全性監視モジュール
git clone https://github.com/zhouchangxun/ngx_healthcheck_module.git --depth 1 -b v1.0 health-check-module
# セッション維持(sticky session)対応モジュール
git clone https://github.com/zhouchangxun/nginx-sticky-module-ng.git --depth 1 sticky-module
# トラフィック可視化モジュール群(HTTP/Stream 向け)
git clone https://github.com/Grim-lock/nginx-module-vts.git --depth 1 -b active_stat vts-module
git clone https://github.com/Grim-lock/nginx-module-sts.git --depth 1 -b active_stat http-sts-module
git clone https://github.com/Grim-lock/nginx-module-stream-sts.git --depth 1 -b active_stat stream-sts-module
ビルド依存パッケージのインストール
コンパイルに必要な開発ライブラリを事前に導入します。
yum install -y zlib-devel pcre2-devel openssl-devel gcc make
カスタムビルド実行
各モジュールのパスを明示的に指定し、デバッグサポートを有効化した状態で構成・コンパイルを行います。
cd nginx-core
./auto/configure \
--prefix=/opt/nginx-custom \
--sbin-path=/usr/local/bin/nginx \
--modules-path=/opt/nginx-custom/modules \
--conf-path=/etc/nginx-custom/nginx.conf \
--error-log-path=/var/log/nginx-custom/error.log \
--http-log-path=/var/log/nginx-custom/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client_body \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--pid-path=/run/nginx-custom.pid \
--lock-path=/run/lock/subsys/nginx-custom \
--with-stream \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-debug \
--add-module=../health-check-module \
--add-module=../sticky-module \
--add-module=../stream-sts-module \
--add-module=../http-sts-module \
--add-module=../vts-module
make -j$(nproc) && sudo make install
基本設定ファイル例(nginx.conf)
モジュール機能を活用した最小限の動作確認用設定です。
user nginx;
worker_processes auto;
error_log /var/log/nginx-custom/error.log warn;
pid /run/nginx-custom.pid;
events {
worker_connections 2048;
}
http {
include /etc/nginx-custom/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx-custom/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
# VTS トラフィック監視初期化
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_set_key $server_name:$server_port;
# ローカル監視エンドポイント
server {
listen 127.0.0.1:8080;
server_name _;
location /monitor/http {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
location /monitor/http/json {
vhost_traffic_status_display;
vhost_traffic_status_display_format json;
}
location /monitor/stream {
stream_server_traffic_status_display;
stream_server_traffic_status_display_format html;
}
location /monitor/health {
check_status;
}
}
include /etc/nginx-custom/conf.d/*.conf;
}
stream {
# Stream トラフィック監視初期化
server_traffic_status_zone;
include /etc/nginx-custom/stream.d/*.conf;
}
ビルド時オプションの確認方法
インストール済みバイナリから使用された configure 引数を抽出するには、以下のようにパイプ処理します。
nginx -V 2>&1 | tr ' ' '\n' | grep '^--'