1

Similar Question: Amazon S3 downloads index.html instead of serving

I am trying to upload a directory to my S3, when I upload manually I can see as static web page. But when I upload using curl, the index.html is getting downloaded.

When I curl my request curl -I https://s3-eu-west-1.amazonaws.com/bucket_name/index.html, I can see

HTTP/1.1 200 OK
x-amz-id-2: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
x-amz-request-id: XXXXXXXXXXXXXXXX
Date: Fri, 15 Mar 2019 21:03:50 GMT
Last-Modified: Fri, 15 Mar 2019 20:53:05 GMT
ETag: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Accept-Ranges: bytes
Content-Type: text/html
Content-Length: 48210
Server: AmazonS3

But still the index.html is downloading.

j08691
  • 204,283
  • 31
  • 260
  • 272

2 Answers2

0

You must configure the relevant bucket for website hosting:

  1. Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. In the list, choose the bucket that you want to use for your hosted website.

  3. Choose the Properties tab.

  4. Choose Static website hosting, and then choose Use this bucket to host a website.

  5. You are prompted to provide the index document and any optional error documents and redirection rules that are needed.

For information about what an index document is, see Configuring Index Document Support.

esqew
  • 42,425
  • 27
  • 92
  • 132
  • Update: When I tried to hit the link on an incognito window, I can see the html as webpage. But few css are missing. Thanks for the reply @esqew, I have enabled website hosting for my bucket and I am able to host a static web page now, but I see some css rendering issues. I am uploading css file with this content-type="text/css". Is there any way to upload all type of files to S3 with common headers. – sridhar13Automation Mar 18 '19 at 17:26
  • You might need to provide more specific details or ask another question; what errors are you seeing in the browser console? – esqew Mar 18 '19 at 17:29
  • I can see the webpage on browser but not with correct styling. I opted to upload files to S3 using AWS CLI and it is working fine now. I can see my static web page with correct styling. Thanks. – sridhar13Automation Mar 18 '19 at 21:44
0

If you click on the file on AWS S3 console and go to Properties tab details of the file, you will see Metadata section

Remove the existing "Content-Type" metadata entry and retype it as "text/html"

If you have configured your S3 as a static web site hosting, now the file will be displayed with its HTML content instead of forcing the browser to download it

Eralper
  • 6,461
  • 2
  • 21
  • 27