-
install prerequisites
yum install zlib-devel pcre-devel geoip-devel openssl-devel libxml2-devel libxslt-devel gd-devel
-
compile arguments
./configure \ --user=nginx \ --group=nginx \ --build=build_name \ --prefix=/usr/local/nginx \ --sbin-path=/usr/local/nginx/sbin/nginx \ --conf-path=/usr/local/nginx/conf/nginx.conf \ --error-log-path=/usr/local/nginx/logs/error.log \ --http-log-path=/usr/local/nginx/logs/access.log \ --pid-path=/usr/local/nginx/logs/nginx.pid \ --lock-path=/usr/local/nginx/logs/nginx.lock \ --modules-path=/usr/local/nginx/modules \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --with-compat \ --with-file-aio \ --with-threads \ --with-pcre-jit \ --with-http_addition_module \ --with-http_auth_request_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_image_filter_module=dynamic \ --with-http_random_index_module \ --with-http_realip_module \ --with-http_secure_link_module \ --with-http_slice_module \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_sub_module \ --with-http_v2_module \ --with-http_xslt_module=dynamic \ --with-http_geoip_module=dynamic \ --with-mail \ --with-mail_ssl_module \ --with-stream \ --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --with-debug \ --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' \ --add-dynamic-module=/root/headers-more-nginx-module-0.33 \ --add-dynamic-module=/root/nginx_cookie_flag_module-1.1.0 \ --add-dynamic-module=/root/njs-0.6.2/nginx
-
Sysv service script
#!/bin/env bash # description: Nginx Service Script exe=/usr/local/nginx/sbin/nginx pid=/usr/local/nginx/logs/nginx.pid conf=/usr/local/nginx/conf/nginx.conf case "$1" in start) if [ -f $pid ];then echo "nginx is running ..." exit 1 else echo "nginx is starting ..." $exe -c $conf fi ;; stop) if [ -f $pid ];then echo "nginx is stopping ..." kill -SIGTERM "$(/bin/cat $pid)" rm -f $pid else echo "nginx is not running!" exit 2 fi ;; restart) if $0 stop;then sleep 2 fi $0 start ;; try-restart) if [ ! -f $pid ];then echo "nginx is not runing!" exit 11 fi $0 restart ;; reload) if [ -f $pid ];then echo "nginx is reloading ..." kill -SIGHUP "$(/bin/cat $pid)" else echo "nginx is not running!" exit 3 fi ;; status) if [ -f $pid ];then echo "nginx is running!" else echo "nginx stopped!" fi ;; *) echo "Usage: $0 (start | stop | restart | try-restart | reload | status)" exit 4 ;; esac
-
systemd unit
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)" #ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)" #ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
/etc/systemd/system/nginx.service.d/override.conf[Service] ExecStart= ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
-
signal
killall -SIGHUP nginx # reload killall -SIGQUIT nginx # stop killall -SIGUSR1 nginx # reopen log files killall -SIGUSR2 nginx # 平滑升级