Nginx Proxy Pass S3 specific html file Nginx Proxy Pass S3 specific html file nginx nginx

Nginx Proxy Pass S3 specific html file


In a proxy scenario content type is specified by the origin server (S3 in this case), unless overridden. You can specify mime types on S3 objects when you upload them. If you do it through S3 web interface, make sure you do not uncheck 'Figure out content types automatically'. AWS cli tools also guess mime types automatically, unless specified otherwise. If you use something else to upload the files, you need to consul the corresponding tool's manual/API reference.

Also you could serve you website directly from S3, see Hosting a Static Website on Amazon S3


Not sure if it's still relevant for you, but I'd suggest you serve your CSS and other static files directly from S3 and not via your Nginx. That is, serve your index.html with a proxy_pass as you do now, but the links to the CSS and JS files inside your index.html should be absolute, with your S3 bucket as the domain.

This will both solve your problem here, and would be better for other reasons such as:

  • You'll reduce CPU and network costs from the server running the Nginx.
  • You'll serve your site faster by not going through your own server for every static file request.
  • S3 offers encryption, compression, ability to add a CDN and many other useful features. Unless there's a compelling reason to go through your own server, I'd avoid it.

Note that your users will still view your site via your own domain, it's only the CSS and JS files that will be served from the S3 domain.