Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Nginx Proxy Pass S3 specific html file

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".

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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

about 4 years ago · Santiago Trujillo Report

0

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.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!