Wednesday, March 22, 2017

Nginx Proxy Pass S3 specific html file

Leave a Comment

I there, before i had my files on my localhost and i was able to serve them just fine. Now, i moved my staticfiles to S3, but i want to serve the index.html starter file with a custom domain. From the index.html must be possible to navigate to other .html.

So far i got:

server {     listen 443 ssl http2;     listen [::]:443 ssl http2;     include snippets/letsencrypt.conf;     include snippets/ssl-params.conf;      charset   utf-8;      server_name mydomain;      location / {    proxy_set_header       Host 's3-eu-west-1.amazonaws.com';         proxy_set_header       Authorization '';         proxy_hide_header      x-amz-id-2;         proxy_hide_header      x-amz-request-id;         proxy_hide_header      Set-Cookie;         proxy_ignore_headers   "Set-Cookie";         proxy_intercept_errors on;         set $indexfile         "s3-eu-west-1.amazonaws.com/myprod-bucket/static/js/frontend/build_v0.5/";         proxy_pass             https://$indexfile;          # expires 1y;         log_not_found off;          auth_basic "Restricted Content";         auth_basic_user_file /etc/nginx/.htpasswd_finder;     }  } 

I can't seem to find any examples that work for my case, what am i doing wrong??

UPDATE: i changed this a bit based on http://stackoverflow.com/a/22843758/977622 and i started getting:

Refused to execute script from '../vendor.5ad3d736.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

and

Resource interpreted as Stylesheet but transferred with MIME type text/html: "../styles/main.b812e04a.css".

1 Answers

Answers 1

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

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment