1、安裝
nginx source 源碼包
wget -P $HOME/Downloads/ http://nginx.org/download/nginx-1.16.1.tar.gz
ngx_cache_purge
wget -P $HOME/Downloads http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
more_set_headers
wget -P $HOME/Downloads https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz
decompress
sudo tar zxvf $HOME/Downloads/ngx_cache_purge-2.3.tar.gz -C /usr/local/src
sudo tar zxvf $HOME/Downloads/nginx-1.16.1.tar.gz -C /usr/local/src
sudo tar zxvf $HOME/Downloads/v0.33.tar.gz -C /usr/local/src
mkdir
sudo mkdir -p /data/var/lib/nginx/{body,proxy,fastcgi,scgi,uwsgi}
sudo mkdir -p /data/ttllogs/nginx
Begin to install
sudo apt install build-essential -y
sudo apt-get install libssl-dev libpcre3 libpcre3-dev libxslt-dev libgd-dev libgeoip-dev
cd /usr/local/src/nginx-1.16.1
sudo ./configure --prefix=/usr/local/share/nginx \
--sbin-path=/ttl/local/bin/nginx \
--modules-path=/usr/local/lib/nginx/modules \
--conf-path=/ttl/local/etc/nginx/nginx.conf \
--error-log-path=/data/ttllogs/nginx/error.log \
--http-log-path=/data/ttllogs/nginx/access.log \
--pid-path=/ttl/local/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www-data \
--group=www-services \
--build=Ubuntu16.04.6LTS \
--http-client-body-temp-path=/data/var/lib/nginx/body \
--http-fastcgi-temp-path=/data/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/data/var/lib/nginx/proxy \
--http-scgi-temp-path=/data/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/data/var/lib/nginx/uwsgi \
--with-pcre-jit \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_secure_link_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-debug \
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' \
--add-module=/usr/local/src/ngx_cache_purge-2.3 \
--add-module=/usr/local/src/headers-more-nginx-module-0.33
如果運行這個配置沒毛病,會出現下面的類容:
Configuration summary
+ using threads
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/share/nginx"
nginx binary file: "/ttl/local/bin/nginx"
nginx modules path: "/usr/local/lib/nginx/modules"
nginx configuration prefix: "/ttl/local/etc/nginx"
nginx configuration file: "/ttl/local/etc/nginx/nginx.conf"
nginx pid file: "/ttl/local/nginx/nginx.pid"
nginx error log file: "/data/ttllogs/nginx/error.log"
nginx http access log file: "/data/ttllogs/nginx/access.log"
nginx http client request body temporary files: "/data/var/lib/nginx/body"
nginx http proxy temporary files: "/data/var/lib/nginx/proxy"
nginx http fastcgi temporary files: "/data/var/lib/nginx/fastcgi"
nginx http uwsgi temporary files: "/data/var/lib/nginx/uwsgi"
nginx http scgi temporary files: "/data/var/lib/nginx/scgi"
#開始編譯 - 安裝
sudo make
sudo make install
另見 /home/cmsadmin/.profile
nginx -v
系統回顯:nginx version: nginx/1.16.1 (Ubuntu16.04.6LTS)
配置
sudo vi /etc/systemd/system/nginx.service
[Unit]
Description=A high performance web server and a reverse proxy server(mainline 1.16.1 since 2019-12-11 compiled by jay.wince)
After=network.target
[Service]
Type=forking
PIDFile=/ttl/local/nginx/nginx.pid
ExecStartPre=/ttl/local/bin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/ttl/local/bin/nginx -g 'daemon on; master_process on;'
ExecReload=/ttl/local/bin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /ttl/local/nginx/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
boot start 加入開機啓動
sudo systemctl enable nginx.service
3、參考鏈接