同時処理速度、メモリの軽さが特徴のWebサーバ。
Webサーバ以外にもリバースプロキシとして動かす事も出来る。
ソフトウェア実装としては珍しい、UDPリバースプロキシにも対応している。
# 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
# 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 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
# 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; }
nginxは通常のWebサーバ動作や、リバースプロキシ動作など様々な用途に利用出来る。
用途に応じて必要な設定とディレクティブ指定が変わる為、使う機能に応じて内容を変更する。
同じサーバで違う処理を実装する場合、 "include" を使って設定を外出しすると整理しやすくなる。
stream { access_log /var/log/nginx/access.log basic; error_log /var/log/nginx/error.log info; upstream DNS { hash $remote_addr; server 192.168.0.1:53; server 192.168.0.2:53; } server { listen 10.0.0.1 udp; proxy_pass DNS; proxy_timeout 1s; proxy_responses 1; } }