多層nginx中的壓縮問題 api接口>1M數據的返回瀏覽器 網關

基礎html

 

前端異步請求,局部刷新,加大最大等待時間前端

 

 

nginx開啓壓縮nginx

 

 

進階django

多級nginx的壓縮api

 

實踐測試:app

每級都要開啓壓縮異步

gizp on;ide

最外層開啓,但最內層沒有開啓測試

最外層沒有開啓優化

 

 

最外層、最內層均開啓

 

 

 

實測是2層

api--> nginx version: nginx/1.12.2 --> nginx version: nginx/1.10.3 -->djangoServer

 

最外層(第1層)

# http://nginx.org/en/docs/http/ngx_http_gzip_module.html
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
#gzip_types text/plain application/xml;
gzip_types *;

 

location /api/ {
gzip on;
#add_header Transfer-Encoding 'identity';
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://p2:8080/api/;
}


}

 

最內層(第2層)
# http://nginx.org/en/docs/http/ngx_http_gzip_module.html
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
#gzip_types text/plain application/xml;
gzip_types *;

location / {

proxy_temp_file_write_size 102400k;
if ($http_x_proxy_url = ''){
return 400 '{"status":400,"data":[],"msg":"請檢查header"}';
}
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $http_x_proxy_url;

}
}

 

Module ngx_http_gzip_module http://nginx.org/en/docs/http/ngx_http_gzip_module.html

 注意

Syntax: gzip_types mime-type ...;
Default:
gzip_types text/html;
Context: http, server, location


Syntax: gzip_proxied off | expired | no-cache | no-store | private | no_last_modified | no_etag | auth | any ...;
Default:
gzip_proxied off;
Context: http, server, location

 

前端進階

 

控制請求順序,優化加載時間

相關文章
相關標籤/搜索