Nginx content-type with proxy_pass
13,025
Solved with proxy_pass_header Content-Type;
no idea why nginx would hide the header.
Related videos on Youtube
Author by
Max0999
Updated on September 18, 2022Comments
-
Max0999 over 1 year
I currently use:
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server_tokens off; upstream webapp { server 127.0.0.1:3000; } server { listen 80; location / { proxy_pass http://webapp; proxy_redirect off; proxy_hide_header Content-Type; } } }
The upstream is a nodejs app that serves a bunch of .js files, since none of them have content-type it causes the client-side error
Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
.I have tried to remove the proxy header with hopes that content-type will be added automatically by nginx-proxy from mime.types (which exist).
-
Alexey Ten over 4 yearsOr better configure nginx to serve static files
-
Max0999 over 4 years@AlexeyTen I see that when a curl and print headers the upstream does indeed send the content-type, I shall try to pass that header instead of blocking it with proxy_pass_header.
-
-
Jose L Ugia about 4 yearsIt looks like you were intentionally hiding the header with proxy_hide_header Content-Type;
-
Max0999 over 2 years@JoseLUgia the whole point is that even without
proxy_hide_header Content-Type;
it wouldn't appear, I had to explicitly addproxy_pass_header Content-Type;
for it to work.