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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that S3 can serve a simple index.html file if it's in the root of a bucket, but my need is to serve lots of simple static sites and S3 has a limit of 100 buckets per account, so I have to use nginx and some subdirectories (like, the bucket is always, that I mapped on the domain using a CNAME that points to

These static sites should be accessible from and serve directly the index.html file.

This is my nginx conf:

server {

        listen   80; ## listen for ipv4
        listen   [::]:80 default ipv6only=on; ## listen for ipv6

        server_name *;

        set $subdomain "";

        if ($host ~* "^(.+)\.bar\.com$") {
                set $subdomain $1;
                rewrite ^(.*)$ /$subdomain/index.html last;

        location / {


I'm almost there :) What happens now is that the index.html file is downloaded: I checked with curl and the content-type is octet/strem. I've tried to overwrite the header to text/html and succeeded, but I keep downloading the file.

I believe that my mistake is hardcoding index.html, the index instruction I give is sompletely redundant, I'm not able to make it work.

What I would like nginx to do is to receive, and serve (not download) the html file located in

Can someone help me?


share|improve this question
Mime type is critical, not all http clients rely on file extension. – Anatoly Mar 27 '15 at 13:50
up vote 1 down vote accepted

Check with curl -- what kind of reply come from ?

Pass correct Content-type: text/html when put your files to S3.

s3put -t text/html .... did the trick

share|improve this answer
You sir, seriously rock. – ngw May 17 '11 at 18:40
I have a question posted here.Can you give your inputs on it? – KillABug Sep 14 '13 at 4:15

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.