Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 http://foo.bar.com/test/index.html, the bucket is always foo.bar.com, that I mapped on the domain bar.com using a CNAME that points to foo.bar.com.s3.amazonaws.com).

These static sites should be accessible from subdomain.bar.com 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 *.bar.com;

        set $subdomain "";

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

        location / {
            proxy_pass http://foo.bar.com/;
        }

}

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 test.bar.com, and serve (not download) the html file located in http://foo.bar.com.s3.amazonaws.com/test/index.html

Can someone help me?

TIA

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Check with curl -- what kind of reply come from http://foo.bar.com/ ?

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

 
discard

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.