#author("2018-03-18T23:24:25+09:00","default:nowsky","nowsky")
*NGINX [#vcddd263]
同時処理速度、メモリの軽さが特徴のWebサーバ。
Webサーバ以外にもリバースプロキシとして動かす事も出来る。
ソフトウェア実装としては珍しい、UDPリバースプロキシにも対応している為、
実装要件によってはNGINXを使って全ての環境を構築する事がある。
~
*参考サイト [#o7c2afd5]
-[[nginx news:+http://nginx.org/]]
-[[Nginxをソースコードからインストール:+https://qiita.com/HayneRyo/items/eccc36302623088ad7f3]]
~
*インストール [#f720ffa6]
-&size(16){&font(b){1. インストール};};
nginxの全機能を利用するにはソースコードからプログラムをビルドする必要がある。
特に、リバースプロキシなど最新の実装機能を利用する場合には必須となる。
今回は機能を全部載せる為、configureオプションが長くなる事から別ファイル化を行い、
configureする時にコマンド置換(バッククォート、ダラー・丸括弧)で読み込む方式を取る。
 # vi configure.option
 ---
 --prefix=/usr/local/nginx-1.13.9
 --with-select_module
 --with-poll_module
 --with-threads
 --with-file-aio
 --with-http_ssl_module
 --with-http_v2_module
 --with-http_realip_module
 --with-http_addition_module
 --with-http_xslt_module
 --with-http_geoip_module
 --with-http_gunzip_module
 --with-http_gzip_static_module
 --with-http_auth_request_module
 --with-http_secure_link_module
 --with-http_degradation_module
 --with-http_slice_module
 --with-http_stub_status_module
 --with-mail
 --with-mail_ssl_module
 --with-stream
 --with-stream_ssl_module
 --with-stream_realip_module
 --with-stream_geoip_module
 --with-stream_ssl_preread_module
 --with-cpp_test_module
 --with-compat
 --with-pcre
 --with-pcre-jit
 --with-libatomic
 
 # wget http://nginx.org/download/nginx-1.13.9.tar.gz
 # tar zxvf nginx-1.13.9.tar.gz
 # cd nginx-1.13.9
 # ./configure `cat ../configure.option | tr '\r\n' ' '`
 # make && make install
 
-&size(16){&font(b){2. 起動準備};};
実行ユーザ、systemdスクリプト、ログローテート設定を準備する。
systemdスクリプトにPIDファイルを埋め込んでいる為、
後で作成するコンフィグのPID指定もsystemdに記載した物と合わせる。
 # vi /usr/lib/systemd/system/nginx.service
 ---
 [Unit]
 Description=NGINX - Web server and Reverse proxy
 Documentation=http://nginx.org/en/docs/
 After=local-fs.target remote-fs.target network.target nss-lookup.target
 
 [Install]
 WantedBy=multi-user.target
 
 [Service]
 Type=forking
 NotifyAccess=all
 PIDFile=/var/run/nginx.pid
 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf
 ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
 ExecReload=/bin/kill -s HUP $MAINPID
 ExecStop=/bin/kill -s QUIT $MAINPID
 
 ## Security Setting
 DevicePolicy=closed
 PrivateDevices=true
 PrivateTmp=true
 ProtectSystem=full
 ProtectHome=true
 
 # vi /etc/logrotate.d/nginx
 ---
 /var/log/nginx/*.log {
     weekly
     compress
     rotate 4
     missingok
     ifempty
     sharedscripts
     postrotate
         /bin/systemctl restart nginx > /dev/null 2>/dev/null || true
     endscript
 }
 
 # ln -s /usr/local/nginx-1.13.9 /usr/local/nginx
 # ln -s /usr/local/nginx/conf /etc/nginx
 # rm /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf
 # mkdir /var/log/nginx
 # groupadd nginx
 # useradd -g nginx -s /sbin/nologin -d /var/nginx nginx
 # systemctl unmask nginx
 # systemctl enable nginx
 
-&size(16){&font(b){3. 基礎設定};};
nginxは利用する機能に応じてコンフィグの内容が大きく変化する。
下記では、nginxの実行ユーザなど基本的な部分のみ記載する。
 # vi /etc/nginx/nginx.conf
 ---
 user       nginx;
 pid        /var/run/nginx.pid;
 error_log  /var/log/nginx/error.log;
 
 worker_processes       auto;
 worker_rlimit_nofile   4096;
 
 events {
     worker_connections 1024;
     accept_mutex_delay 50ms;
     multi_accept       on;
     use                epoll;
 }
~
*コンフィグ [#l50c23aa]
nginxは通常のWebサーバ動作や、リバースプロキシ動作など様々な用途に利用出来る。
用途に応じてコンフィグも大きく変わってくる為、記述内容を都度変更する必要がある。
-&size(16){&font(b){UDPリバースプロキシ};};
作成中...