【发布时间】:2021-10-21 10:49:37
【问题描述】:
我有一个 nginx 反向代理,它将所有请求转发到服务器,然后将 (301) 重定向到 aws 服务。请求返回的 pdb 文件可能非常大,通常可能会多次调用同一个请求,因此缓存响应会很好。
我的问题是,似乎不是缓存“文件”,而是缓存重定向本身而不是响应,因为缓存文件远不及实际文件的大小,并且请求时间的增益是比我尝试不使用重定向要少得多。
我想知道是否有办法避免这种行为并每次都缓存响应。
这是我的配置
user nginx;
worker_processes 1;
events {
worker_connections 10240;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
proxy_cache_path /var/cache/nginx keys_zone=one:10m use_temp_path=off;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://server.org/;
proxy_redirect off;
proxy_cache one;
proxy_http_version 1.1;
proxy_intercept_errors on;
proxy_cache_key $scheme$request_uri;
proxy_cache_valid any 24h;
}
}
}
【问题讨论】:
标签: http nginx caching https nginx-reverse-proxy