Welcome! Log In Create A New Profile

Advanced

setting cache proxy on aws ec2

Posted by alonP 
setting cache proxy on aws ec2
June 30, 2015 09:08PM
Hi

I am trying to set a cache proxy to s3, and was following examples I have found on the web - I am retrieving the file but the cacheing is not being done. I have enabled debug but I am not sure what is going inside

here is my config:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;
#error_log /var/log/nginx/error.log debug;
# Make site accessible from http://localhost/
server_name localhost;

location ~* ^/public_proxy/(.*) {
set $s3_bucket 'alon-test.s3-us-west-2.amazonaws.com';
set $url_full '$1';

proxy_http_version 1.1;
proxy_set_header Host $s3_bucket;
proxy_set_header Authorization '';
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_hide_header Set-Cookie;
proxy_ignore_headers "Set-Cookie";
proxy_buffering off;
proxy_intercept_errors on;

proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args";
proxy_cache s3cache;
proxy_cache_valid any 60m;

proxy_pass http://$s3_bucket/$url_full;
}


I am calling:
wget http://localhost/public_proxy/higayon.pdf

Thanks
Alon
Re: setting cache proxy on aws ec2
July 06, 2015 09:53AM
Hello,

I am not pretty sure, it is a good idea to cache into s3 bucket. Even it is just a proxy cache.
because the objective of cache in general thinking is to access the nearest resources with lowest latency
which is its local storage or memory.

correct me if I am wrong,
when I am looking at your configuration, I get that you want to do reverse proxy to s3 bucket.
>>proxy_pass http://$s3_bucket/$url_full;
if that is the case I am not suggesting you to use proxy cache from s3 bucket also. because that mean your proxy cache is basically the same resource or origin from your actual resource.

I suggest you to change your proxy cache location to your local storage or just leave it default. except you have some other problem with nginx proxy cache default configuration.
Re: setting cache proxy on aws ec2
July 06, 2015 02:12PM
Hi

maybe I got confused here, so let me try to explain what I am trying to do:

user <-obj get-> ec2 <-obj get->s3
this is the general flow in which user access objects stored on s3 through ec2 url, nginx provide the ability for url masking.

inorder to utilize this i am trying to save objects (cache them?) on ec2 so that the next time this object will served it will be through the ec2 without accessing s3.
user <-obj get-> ec2 <-obj get->ec2 local cache

currently, with the above config, the url masking works fine, the problem is the the caching is not working.
here is the other (defualt) part of the config:

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=s3-cache:8m max_size=1000m inactive=600m;
proxy_temp_path /var/cache/nginx/tmp;

thanks for the help
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 92
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready