準(zhǔn)備過程
下載PCRE庫(pcre2可能還不支持),并解壓
下載zlib庫拓挥,并解壓
下載Nginx的最新代碼袋励,解壓
wget http://nginx.org/download/nginx-1.18.0.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
編譯安裝過程
# ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=../pcre-8.44 --with-zlib=../zlib-1.2.11 --add-module=../nginx-upload-module
# make && make install
附錄
--prefix #nginx安裝目錄,默認(rèn)在/usr/local/nginx
--pid-path #pid問件位置茬故,默認(rèn)在logs目錄
--lock-path #lock問件位置,默認(rèn)在logs目錄
--with-http_ssl_module #開啟HTTP SSL模塊赁炎,以支持HTTPS請求钾腺。
--with-http_dav_module #開啟WebDAV擴(kuò)展動作模塊,可為文件和目錄指定權(quán)限
--with-http_flv_module #支持對FLV文件的拖動播放
--with-http_realip_module #支持顯示真實(shí)來源IP地址
--with-http_gzip_static_module #預(yù)壓縮文件傳前檢查姻报,防止文件被重復(fù)壓縮
--with-http_stub_status_module #取得一些nginx的運(yùn)行狀態(tài)
--with-mail #允許POP3/IMAP4/SMTP代理模塊
--with-mail_ssl_module #允許POP3/IMAP/SMTP可以使用SSL/TLS
--with-pcre=pcre-8.39 #注意是未安裝的pcre路徑间螟,pcre2 不能通過
--with-zlib=zlib-1.2.5 #注意是未安裝的zlib路徑
--with-openssl=openssl-1.1.1c #未安裝的openssl
--with-debug #允許調(diào)試日志
--http-client-body-temp-path #客戶端請求臨時文件路徑
--http-proxy-temp-path #設(shè)置http proxy臨時文件路徑
--http-fastcgi-temp-path #設(shè)置http fastcgi臨時文件路徑
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #設(shè)置uwsgi 臨時文件路徑
--http-scgi-temp-path=/var/tmp/nginx/scgi #設(shè)置scgi 臨時文件路徑
增加 upload-module:
git clone https://github.com/fdintino/nginx-upload-module.git
configure 時加入?yún)?shù) --add-module=../nginx-upload-module
Add to service
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
ExecQuit=/usr/sbin/nginx -s quit
PrivateTmp=false
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start nginx.service
Nginx Cache
proxy_cache_path /tmp/cache levels=1:2 keys_zone=nuget-cache:20m max_size=10g inactive=168h;
server {
....
location /cache/ {
proxy_cache nuget-cache;
proxy_cache_valid 168h;
proxy_ignore_headers Set-Cookie Cache-Control;
proxy_hide_header Cache-Control;
proxy_hide_header Set-Cookie;
proxy_cache_key $host$uri$is_args$args;
proxy_pass http://tomcat/path/;
}
....