Dynamic Upstream

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Dynamic Upstream

rnburn
Pupose: Need to create a local proxy to an image cdn (Beats the purpose of
having a CDN, but can't help!!)

Setup: I have a cdn setup with multiple endpoints say t1.mycdn.com,
t2.mycdn.com and t3.mycdn.com. I have a website (foobar.com) which uses
images from these cdns. Because of some requirement, I need to have
localized path to images (say https://foobar.com/images/sellers/s1/22.jpg).
I need to proxy pass it to my 3 cdn endpoints with equal weight. Along the
way, I need to change the URL too,
https://foobar.com/images/sellers/s1/22.jpg will be fetched from
t1.mycdn.com/img/slr/s1/22.jpg OR t2.mycdn.com/img/slr/s1/22.jpg OR
t3.mycdn.com/img/slr/s1/22.jpg with equal probability.

I have compiled nginx with the following config
configure arguments: --prefix=/opt/nginx
--pid-path=/home/ec2-user/pids/nginx.pid --user=ec2-user --group=ec2-user
--without-http_autoindex_module --without-http_geo_module
--without-http_memcached_module --without-http_scgi_module
--without-http_uwsgi_module --with-http_realip_module
--with-http_addition_module --with-http_xslt_module --with-http_geoip_module
--with-http_sub_module --with-http_gzip_static_module
--with-http_stub_status_module --with-http_secure_link_module
--without-mail_pop3_module --with-http_v2_module --without-mail_imap_module
--without-mail_smtp_module --with-http_ssl_module
--add-module=/tmp/ngx_devel_kit-0.3.0
--add-module=/tmp/lua-nginx-module-0.10.7
--add-module=/tmp/echo-nginx-module-0.60
--add-module=/tmp/set-misc-nginx-module-0.31
--add-module=/tmp/headers-more-nginx-module-0.32
--with-ld-opt=-Wl,-rpath,/opt/luajit/lib

Current Approach: I have the following block
location ~* ^/images/sellers/[^/]+/[^/]+$ {
  error_log /tmp/images.log debug;
  set $img_host "";
  set $img_url "";
  rewrite_by_lua '
    math.randomseed(os.time())
    ngx.var.img_host = "t"..math.random(1,3)..".mycdn.com"
    ngx.var.img_url = string.gsub(ngx.var.uri, "/images/sellers",
"/img/slr/")
  ';
  proxy_set_header HOST $img_host;
  proxy_pass https://$img_host$img_url;
}

When I try to fetch the image, I keep getting the following error

invalid URL prefix in "https://"

I tried changing https to http too. Doesn't help. Can you please let me know
where am I going wrong here ?

Thanks,
Bhargava

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273963,273963#msg-273963

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx