I there, before I had my files on my localhost and I was able to serve them just fine. Now, I moved my static files 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 https://stackoverflow.com/a/22843758/977622 and I started getting:
Refused to execute the 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".
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:
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.