Followwing是nginx的一部分,nginx不适用于.gz扩展名,只有nginx不会保存缓存的数据,而是每个从后端服务器(upstreadm)填满的请求,在img文件和其他扩展名中也是如此。 我想要的是nginx首先将文件缓存到服务器,如果不在缓存中,则转到上游服务器从那里拉取文件。
location ~ \.(?:okl)$ {
proxy_temp_file_write_size 800k;
proxy_temp_path /usr/local/nginx/proxy_temp;
gzip_static on;
expires 30d;
add_header 'Access-Control-Allow_Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
proxy_buffers 16 4k;
proxy_buffer_size 2k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Accept-Encoding "";
rewrite ^/(.*)$ /$1.gz break;
proxy_cache_bypass $http_cachepurge; # mand
# proxy_cache_bypass $admin_user;
#proxy_set_header Accept */*;
#proxy_set_header Accept-Encoding "gzip, deflate, br";
proxy_pass https://localhost;#
proxy_cache_bypass $http_cachepurge; # mand
proxy_cache cache;
#configure header for retrieving .gz and
#proxy_hide_header Content-Type;
add_header Content-Type text/plain always;
add_header Content-Type application/javascript always;
add_header Content-Encoding gzip;
add_header Transfer-Encoding gzip;
add_header X-Frame-Options: deny;
# You might want to hide the following headers:
proxy_hide_header x-bz-file-name;
proxy_hide_header x-bz-file-id;
proxy_hide_header x-bz-content-sha1;
proxy_hide_header x-Bz-Upload-Timestamp;
proxy_hide_header x-bz-info-src_last_modified_millis;
}
##### GZIP FILED SERVERED
location ~ \.(?:gz)$ {
proxy_temp_file_write_size 800k;
proxy_temp_path /usr/local/nginx/proxy_temp;
gzip_static on;
expires 30d;
add_header 'Access-Control-Allow_Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
proxy_buffers 16 4k;
proxy_buffer_size 2k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Accept-Encoding "";
# rewrite ^/(.*)$ /$1.gz break;
# proxy_cache_bypass $http_cachepurge; # mand
# proxy_cache_bypass $admin_user;
#proxy_set_header Accept */*;
#proxy_set_header Accept-Encoding "gzip, deflate, br";
proxy_pass http://backend;
proxy_cache_bypass $http_cachepurge; # mand
proxy_cache cache;
#configure header for retrieving .gz and
proxy_hide_header Content-Type;
#add_header Content-Type text/plain always;
add_header Content-Type application/javascript always;
add_header Content-Encoding gzip;
add_header Transfer-Encoding gzip;
add_header X-Frame-Options: deny;
# You might want to hide the following headers:
proxy_hide_header x-bz-file-name;
proxy_hide_header x-bz-file-id;
proxy_hide_header x-bz-content-sha1;
proxy_hide_header x-Bz-Upload-Timestamp;
proxy_hide_header x-bz-info-src_last_modified_millis;
}