1

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_pass http://s3-eu-west-1.amazonaws.com/usta/html/;
    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?

1 Answer 1

2

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 static.example.com, 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:

2
  • Not possible when you need more DNS records than CNAME (e.g. when it's on your top-level domain, foo.com, 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, 2015 at 19:43
  • But if you want to restrict access to your static site to be behind a VPN, yo can't using S3 website, so you must go with Nginx implementation
    – ctaglia
    Mar 23, 2023 at 12:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .