Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Im using Nginx front-end server in front of glassfish app. server. I uploaded my static contents to Amazon S3. I need to implement passing static request to Amazon's URL. I did a conf file like below.

    location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
    access_log off;
    expires max;    
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


But with reqular expression, i couldnt proxy request to Amazon s3 URL, how can i implement this idea?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This would be an inefficient solution because all requests for static content would still be going to your Nginx server, costing you unnecessary bandwidth and CPU.

The better solution is to store and reference your static content as, and then associate your domain name with your S3 bucket. Then your static content could be efficiently served directly from S3, while still appearing to be hosted at your domain name.

Also see this related question:

share|improve this answer
Not possible when you need more DNS records than CNAME (e.g. when it's on your top-level domain,, and you need mail records etc.). This is when you need to use an A record, and when nginx becomes useful for proxying S3. – aehlke Aug 7 at 19:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.