Nginx自動回源配置

2022-04-09 02:11:27 字數 2422 閱讀 5015

1.背景

為了解決每次軟體版本更新,導致辦公網公網頻寬緊張,通過nginx回源至本地機房,網域名稱解析採用內外網單獨解析,外地辦公同事可以通過cdn進行更新,公司內部同事通過內網dns解析獲取本地資源更新

nginx常見的回源方式nginx proxy_store或proxy_cache模組

2.proxy_store方式回源

以下是nginx回源配置:

server 

}error_page 500 502 503 504 /50x.html;

location = /50x.html

location /ngx_stat

}

3.proxy_cache方式回源

以下是nginx回源配置:

重點關注proxy_cache配置

#nginx 主配置檔案

vim nginx.conf

#定義nginx執行的使用者和使用者組

#啟動程序,通常設定成和cpu的數量相等

worker_processes auto;

#改指令是當義工nginx程序開啟的最多檔案描述符數目,理論值應該是最多開啟檔案數(ulimit -n)

#與nginx程序數相除,但是nginx分配請求並不是那麼均勻,所以最好與ulimit -n的值保持一致

#全域性訪問日誌,採用json日誌格式

access_log /data/logs/nginx/access.log json;

#全域性錯誤日誌

#錯誤日誌定義等級,預設error級別,[ debug | info | notice | warn | error | crit ]

error_log /data/logs/nginx/error.log;

#sendfile指令制定nginx是否呼叫sendfile函式(zero copy方式)來輸出檔案

#對於普通應用必須設為on

#降低系統的uptime

sendfile on;

#防止網路阻塞

tcp_nopush on;

#提高資料的實時響應性

tcp_nodelay on;

#隱藏nginx版本號

server_tokens off;

#keepalive超時時間,客戶端到伺服器端的連線持續有效時間,當出現對伺服器的後端請求時,

#keepalive-timeout功能可避免建立或重新建立連線

keepalive_timeout 65;

#定義讀取客戶端請求標頭的超時。如果客戶端在此時間內未傳輸整個標頭,

#則請求將以408(請求超時)錯誤終止

client_header_timeout 15;

#定義讀取客戶端請求正文的超時。如果客戶端在此時間內未傳輸任何內容,

#則請求會因408(請求超時)錯誤終止

client_body_timeout 15;

#後端伺服器資料回傳時間(**傳送超時)

send_timeout 25;

client_header_buffer_size 4096k;

#允許客戶端請求的最大單檔案位元組數

client_max_body_size 10m;

proxy_cache_path /data/nginx/proxy_cache/cache levels=1:2 keys_zone=downloadcache:600m max_size=400g inactive=48h use_temp_path=on;

proxy_temp_path /data/nginx/proxy_cache/temp;

proxy_cache_key $host$request_uri;

#開啟gzip壓縮

#gzip on;

#gzip_min_length 1k;

#gzip_buffers 4 16k;

#壓縮級別大小,最大為9,值越小,壓縮後比例越小,cpu處理更快,值越大,消耗cpu比較高

#gzip_comp_level 2;

#gzip_vary off;

include /usr/local/nginx/conf/vhost/*.conf;

}#虛擬主機配置檔案

vim default.conf

server

error_page 500 502 503 504 /50x.html;

location = /50x.html

location /ngx_stat

}

4.大檔案回源方法

針對大檔案回源可以採用360開源的ngx_http_subrange_module模組

自動配置yum源倉庫

1 自動配置yum源倉庫 安裝yum的擴充套件包 yum install yum utils y 自動配置國內epel倉庫 yum config manager add repo 自動配置完畢後,檢視配置的yum源 vim etc yum.repo.d mirrors.tuna.tsinghua.e...

VC自動配置資料來源

要注意的是,當我們使用sqlconfigdatasource odbc api函式時必須宣告包含系統的odbcinst.h標頭檔案,所以我們再選擇workspace視窗中fileview開啟header files中try.h,在其中加入 include odbcinst.h 如果不加入這個標頭檔案...

配置 Nginx 自動切割日誌

第一種方法 mv opt nginx logs access.log opt nginx logs access date y m d log killall s usr1 nginx 使用usr1引數通知nginx程序切換日誌檔案 將以上指令碼內容儲存為檔名為 logcron.sh 存到自定的目錄...