Skip to content

Instantly share code, notes, and snippets.

@Hexa
Created December 20, 2013 15:30
Show Gist options
  • Select an option

  • Save Hexa/8056383 to your computer and use it in GitHub Desktop.

Select an option

Save Hexa/8056383 to your computer and use it in GitHub Desktop.
location / {
set $aws_access_key_id "";
set $aws_secret_access_key "";
set $bucket_name "bucket";
mruby_set_code $date "Nginx::Time.http_time(Nginx::Time.time)";
mruby_set_code $authorization '
content_md5 = ""
content_type = ""
request = Nginx::Request.new
var = Nginx::Var.new
string_to_sign = request.method + "\n" +
content_md5 + "\n" +
content_type + "\n" +
var.date + "\n" +
"/" + var.bucket_name + request.uri
hmac_sha1 = Nginx::Digest.hmac_sha1(string_to_sign, var.aws_secret_access_key)
"AWS " + var.aws_access_key_id + ":" + Nginx::Base64.encode(hmac_sha1)
';
resolver 192.168.1.1;
proxy_set_header Host $bucket_name.example.com;
proxy_set_header Date $date;
proxy_set_header Authorization $authorization;
proxy_pass http://$bucket_name.example.com:8080$uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment