I'm wondering what I'm missing in my nginx configuration that is causing these errors to occur in the browser console and preventing the site from rendering nicely.
I've set up what I thought was a working nginx configuration for a new Linode (Ubuntu 18.04 LTS, Plone 5.2 (yes!), Python 3.6.8), and letsencrypt (certbot is very nice).
But my site isn't rendering nicely because I'm getting many errors like this appearing in the browser (Firefox) console:
The script from “https://plone.oshcom.net/++plone++static/++unique++2019-07-20%2013%3A21%3A37.502871/plone-base-compiled.min.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
That is if I do not have this in the nginx configuration:
add_header X-Content-Type-Options "nosniff";
If I do have "nosniff" set, I get many of these errors:
The resource from “https://plone.oshcom.net/++plone++static/components/jquery/dist/jquery.min.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
Loading failed for the <script> with source “https://plone.oshcom.net/++plone++static/components/jquery/dist/jquery.min.js”.
The page that Mozilla links to, as an explanation for these errors is:
My nginx configuration file is:
add_header X-Frame-Options "SAMEORIGIN";
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
add_header Content-Security-Policy "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'";
upstream plone52 {
server 127.0.0.1:8080;
}
server {
server_name plone.oshcom.net;
access_log /var/log/nginx/plone.access.log;
error_log /var/log/nginx/plone.error.log;
set $vh_protocol "https";
set $vh_port "443";
location / {
auth_basic off;
proxy_pass http://plone52/VirtualHostBase/$vh_protocol/$server_name:$vh_port/Plone/VirtualHostRoot/;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/plone.oshcom.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/plone.oshcom.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = plone.oshcom.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name plone.oshcom.net;
return 404; # managed by Certbot
}
the resources where missing.
After debugging nginx, I found out that, the request to the backend was missing the $request_uri parameters. So I changed it to:
It seems that nginx handles the rule in a diffenrent way when you add variables there, as the rule was working like this with the static host string in it.