Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
config for nginx to proxy a specific path to an S3 bucket
# copied from default config
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
# this is where the magic starts:
location /static {
proxy_set_header Host 'YOURBUCKET.s3-website.eu-central-1.amazonaws.com';
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_intercept_errors on;
proxy_pass http://YOURBUCKET.s3-website.eu-central-1.amazonaws.com;
log_not_found off;
}
location /static/images {
proxy_set_header Host 'YOURBUCKET.s3-website.eu-central-1.amazonaws.com';
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_intercept_errors on;
proxy_pass http://YOURBUCKET.s3-website.eu-central-1.amazonaws.com/images;
}
}
}
@acrolink

This comment has been minimized.

Copy link

@acrolink acrolink commented Aug 17, 2019

Thank you. Is there a way to make it possible to provide an index of the files stored in a given path in a s3 bucket? using Nginx?

One possibility is to mount the bucket as s3fs and indexing the folders using Nginx, but is is possible to do that without s3fs?

@cibinmathew

This comment has been minimized.

Copy link

@cibinmathew cibinmathew commented Nov 21, 2020

Does this impact CORS. Is there any additional config required in S3/nginx if in S3, AllowedOrgin is set to '*' .

@TomTasche

This comment has been minimized.

Copy link
Owner Author

@TomTasche TomTasche commented Nov 21, 2020

Does this impact CORS. Is there any additional config required in S3/nginx if in S3, AllowedOrgin is set to '*' .

No, I don't think so. nginx would forward the necessary headers if they're set by S3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment