Nginx 編譯安裝

準備過程

下載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安裝目錄,默認在/usr/local/nginx
--pid-path #pid問件位置,默認在logs目錄
--lock-path #lock問件位置,默認在logs目錄
--with-http_ssl_module #開啟HTTP SSL模塊,以支持HTTPS請求。
--with-http_dav_module #開啟WebDAV擴展動作模塊,可為文件和目錄指定權限
--with-http_flv_module #支持對FLV文件的拖動播放
--with-http_realip_module #支持顯示真實來源IP地址
--with-http_gzip_static_module #預壓縮文件傳前檢查,防止文件被重復壓縮
--with-http_stub_status_module #取得一些nginx的運行狀態
--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 #允許調試日志
--http-client-body-temp-path #客戶端請求臨時文件路徑
--http-proxy-temp-path #設置http proxy臨時文件路徑
--http-fastcgi-temp-path #設置http fastcgi臨時文件路徑
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #設置uwsgi 臨時文件路徑
--http-scgi-temp-path=/var/tmp/nginx/scgi #設置scgi 臨時文件路徑

增加 upload-module:
git clone https://github.com/fdintino/nginx-upload-module.git
configure 時加入參數 --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/;
       }
....
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容