Skip to content

Instantly share code, notes, and snippets.

@zefer
Created March 9, 2011 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zefer/862006 to your computer and use it in GitHub Desktop.
Save zefer/862006 to your computer and use it in GitHub Desktop.
my full conf for allowing S3 CORS file uploads
# DO NOT RESPOND TO REQUESTS OTHER THAN upload.xxx.ly AND upload.xxx.com
server {
listen 80 default;
server_name _;
return 444;
}
# FILE UPLOADS
server {
listen 80;
server_name upload.xxx.ly upload.xxx.com;
access_log /var/log/nginx/s3uploadproxy.access.log;
error_log /var/log/nginx/s3uploadproxy.error.log;
proxy_read_timeout 10;
proxy_connect_timeout 10;
# allow big files...
client_max_body_size 30M;
# and slow uploads
proxy_send_timeout 1200;
# Deny illegal Host headers
if ($host !~* ^(upload.xxx.ly|upload.xxx.com)$ ) {
return 444;
}
# dissalow methods
if ($request_method !~ ^(OPTIONS|POST)$ ) {
# empty response
return 444;
}
location / {
# CORS PRE-FLIGHT REQUESTS
if ($request_method = 'OPTIONS') {
more_set_headers 'Access-Control-Allow-Origin: *';
more_set_headers 'Access-Control-Allow-Methods: POST, OPTIONS';
more_set_headers 'Access-Control-Max-Age: 1728000';
more_set_headers 'Content-Type: text/plain; charset=UTF-8';
#more_set_headers 'Access-Control-Allow-Headers: ';
return 200;
}
# FILE UPLOADS
if ($request_method = 'POST') {
more_set_headers 'Access-Control-Allow-Origin: *';
proxy_pass http://img.xxx.ly;
}
}
# 204 (No Content) for favicon.ico
location = /favicon.ico {
#empty_gif;
return 204;
}
}
@ejunzen
Copy link

ejunzen commented May 31, 2013

HI, i don't clear with how you can upload file to S3. it seems that you missing some part of nginx.conf. could you provide all of them ? thank you !

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