AWS Beanstalk和缓存上的Nginx反向代理

时间:2020-07-13 17:50:54

标签: nginx amazon-elastic-beanstalk reverse-proxy

我在AWS Beanstalk中设置了一个反向代理。 nginx的目的是从上游Location标头中获取一个值,并将结果与​​原始请求URI的缓存键一起存储,以便将来的客户端也无需遵循重定向。

此处的磁盘空间最多为68G:/ var / nginx / cache,此处为30G:/ var / nginx / temp-cache。因此,我的代理服务器的磁盘空间很快就满了。

任何人都知道如何减少或限制缓存的大小吗?还是如果有一种更有效的更好的方法来使我的磁盘填满的速度不那么快?谢谢。

    worker_processes  1;
user       nginx;
pid        /var/run/nginx.pid;

events {
    worker_connections  65535;
}

worker_rlimit_nofile 30000;

http {
    proxy_cache_path /var/nginx/cache keys_zone=rev-origin:100m levels=1:2 inactive=7d max_size=80g;
    proxy_temp_path /var/nginx/temp-cache;

server {
    listen      80 default_server;
    access_log /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log;
    charset     utf-8;
    client_max_body_size 500M;
    gzip on;
    location / {
      proxy_pass https://123456abc.execute-api.us-east-1.amazonaws.com/AB/;
      proxy_ssl_server_name on;
      proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      proxy_cache       rev-origin;
      proxy_cache_key   $uri;
      proxy_cache_valid 200 206 1d;
      proxy_intercept_errors on;
      recursive_error_pages on;
      error_page 301 302 307 = @handle_redirects;
    }

    location @handle_redirects {
      resolver 8.8.8.8;

      set $original_uri $uri;
      set $orig_loc $upstream_http_location;

      # nginx goes to fetch the value from the upstream Location header
      proxy_pass $orig_loc;
      proxy_cache       rev-origin;
      proxy_intercept_errors on;
      error_page 301 302 307 = @handle_redirect;
      # But we store the result with the cache key of the original request URI
      # so that future clients don't need to follow the redirect too
      proxy_cache_key $original_uri;
      proxy_cache_valid 200 206 3000h;
    }
  }
}

1 个答案:

答案 0 :(得分:0)

在过去的几周中,我通过测试几个模块找到了解决方案。看起来可行并减少缓存大小的方法是使用以下模块:

  proxy_max_temp_file_size 1024m;
  proxy_buffer_size 4k;
  proxy_buffers 4 32k;
  proxy_busy_buffers_size 64k;
  proxy_temp_file_write_size 64k;