Update to readme for NGINX.

For NGINX, add to your server config:

location ~* ^/(s3fs-css|s3fs-js)/(.*) {

  set $s3_bucket 'your_bucketname_and_path';
  set $url_full  $2;

  resolver               8.8.4.4 8.8.8.8 valid=300s;
  resolver_timeout       10s;
  proxy_pass             http://$s3_bucket/$url_full;

}

Reference: https://coderwall.com/p/rlguog/nginx-as-proxy-for-amazon-s3-public-private-files
CommentFileSizeAuthor
#1 s3fs-nginx_settings-2474421-0.patch989 bytesjozzhart

Comments

jozzhart’s picture

Issue summary: View changes
StatusFileSize
new989 bytes
coredumperror’s picture

You've tested this and can confirm that it works? I ask because I don't have nginx, and some of the details here don't seem right (or I'm just not interpreting the config lines correctly).

I'm not sure exactly what the $s3_bucket variable is supposed to contain. I think this would work if it was something like YOUR-BUCKET.s3.amazonaws.com/s3fs-public, but I want to make sure that's what you had in mind, since I'm not positive how this config syntax works.

I'm also curious why the resolver settings are necessary, but that's probably just an nginx configuration detail I'm unaware of.

jozzhart’s picture

Yup, can be seen working here
http://nswinterschools.com.au

Yup, $s3_bucket = YOUR-BUCKET.s3.amazonaws.com/s3fs-public

I'm not a nginx expert, that's why I included the URL reference where I got the resolver config. Further reading here;

http://serverfault.com/a/240485/173119
http://www.nginx-discovery.com/2011/05/day-51-proxypass-and-resolver.html

  • coredumperror committed d8465ad on 7.x-2.x
    Issue #2474421: Updated README to include proxy config for nginx....
coredumperror’s picture

Status: Patch (to be ported) » Fixed

Alright, I pushed this config (with a few tweaks) up to the dev build's README. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

muhaha03’s picture

nothing worth to mention

muhaha03’s picture

change resolver to 8.8.8.8, everything works well finally

muhaha03’s picture

This patch don't actually work.
It still make drupal load local s3fs-css and s3fs-js which not locate at s3.
Only resolver works in this patch.

muhaha03’s picture

it should be like this.

location ~* /(s3fs-css|s3fs-js)/(.*) {
  set $s3_bucket 'devgive543.s3.amazonaws.com/s3fs-public';
  set $url_full  '$2';
  return             https://$s3_bucket/$url_full;
}
muhaha03’s picture

this is wrong

coredumperror’s picture

I'm not sure what the "return" directive does in nginx, but I'm not sure it'll work unless it's performing some kind of proxying. Do you know if it does that?

muhaha03’s picture

I'm not so sure why proxying fail in my case.
But these down below solved my problems.

location ~* /(s3fs-css|s3fs-js)/(.*)$ {
  set $s3_bucket '****.s3.amazonaws.com/s3fs-public';
  set $url_full  '$2';
  rewrite /(s3fs-css|s3fs-js)/(.*)$ http://$s3_bucket/$url_full;
}
laughnan’s picture

Status: Closed (fixed) » Needs work

@muhaha03 #13 fails for me on nginx (but so does the README information). I get a 502 Bad Gateway error.

Doing the rewrite makes several 404's occur (because it pulls the aggregated files from AWS and they have relative paths for theme/module files such as fonts and images which do not exist on S3).

Anyone have thoughts on this?

coredumperror’s picture

Status: Needs work » Closed (fixed)

I wish I could help with this, but I have no experience with nginx.

I can see why #13 is causing the problems you reference in your second paragraph, though. The server config must set up a proxy, not a redirect, due to same-origin policy.

But I haven't got a clue why you'd have a problem with the nginx config from the readme. Maybe you forgot to replace the "YOUR-BUCKET" part of the $s3_base_path with the actual name of your bucket? Or perhaps your bucket name has dots in it? That causes problems with SSL certificates.

Either way, this is not actually the appropriate place to hash out the troubleshooting for the issue you're having, as this is a long-closed feature request ticket. Please open a new bug report ticket, where we can continue this conversation.