Varnish : Varnish not loading CSS and JS.

Danila Vershinin ciapnz at gmail.com
Tue Oct 8 22:36:26 UTC 2019


Hi,

I don't think it's related to Varnish.

1. You should not be using pub/ in your URLs. The secure Magento 2 
setup assumes that pub/ directory is your web root, so you should end 
up with URLs without it.
2. Your CSS/JS is not loaded because they are returning 404s (thus 
text/html MIME type, and browser refuses to load them because they are 
not scripts/styles, they are HTML error message)

On Tue, Oct 8, 2019 at 4:17 PM, Akshay Sulakhe <kernelfreak at gmail.com> 
wrote:
> Hello friends,
> 
> I am running magento 2.2.6 on a nginx server. I have Varnish 
> installed on another dedicated server. When I use it via proxy-pass 
> and contact varnish server first, I am able to load the magento 
> website, but CSS and JS are not loading due to strict mime-type issue.
> 
> Error log :
> 
> pub/static/version123456/frontend/company/default/de_DE/css/styles-1.min.css 
> was blocked due to MIME type ("text/html") mismatch 
> (X-Content-Type-Options: nosniff)
> 
> We don't have no-sniff added in our Nginx configuration.
> 
> Varnish config :
> 
> default.vcl
> 
> backend server1c {
>     .host = "IP1";
>     .port = "80";
>     .probe = {
>           .url = "/balancer.html";
>           .timeout = 500s;
>           .interval = 5s;
>           .window = 5;
>           .threshold = 3;
>     }
> }
> 
> backend server1b {
>     .host = "IP2";
>     .port = "80";
>     .probe = {
>           .url = "/balancer.html";
>           .timeout = 500s;
>           .interval = 5s;
>           .window = 5;
>           .threshold = 3;
>     }
> }
> 
> 
> backend server1a {
>     .host = "IP3";
>     .port = "80";
>     .probe = {
>           .url = "/pub/balancer.html";
>           .timeout = 500s;
>           .interval = 5s;
>           .window = 5;
>           .threshold = 3;
>    }
> }
> 
> sub vcl_recv {
>     # Happens before we check if we have this in cache already.
>     #
>     # Typically you clean up the request here, removing cookies you 
> don't need,
>     # rewriting the request, etc.
>  if (req.url == "/lazyload/prices/load/") {
>         return(pass);
>     }
>     if (req.url == "/roobeo_config/store/changemode/mode/0") {
>         return(pass);
>     }
>       if (req.url == "/roobeo_config/store/changemode/mode/1") {
>         return(pass);
>     }
>   if (req.url == 
> "/rest/default/V1/carts/mine/estimate-shipping-methods") {
>         return(pass);
>     }
>   if (req.url == "/lazywishlist/") {
>         return(pass);
>     }
>   if (req.url == "/index.php/rest/V1/") {
>         return(pass);
>     }
>   if (req.url == "/customer/account/createpassword/") {
>         return(pass);
>     }
>   if (req.url == "/customer/account/resetpasswordpost/") {
>         return(pass);
>     }
>   if (req.url == "/roobeo_shipping/zipcode/validate/") {
>         return(pass);
>     }
>   if (req.url == "/roobeo_shipping/zipcode/save/") {
>         return(pass);
>     }
>   if (req.url == "/roobeo_shipping") {
>         return(pass);
>     }
> }
> 
> sub vcl_init {
>     new bar = directors.round_robin();
>     bar.add_backend(server1a);
>     bar.add_backend(server1b);
>     bar.add_backend(server1c);
> }
> 
> Nginx config :
> 
>  location / {
>         proxy_pass http://VARNISH_IP:80;
>         proxy_set_header Host $http_host;
>         proxy_set_header X-Forwarded-Host $http_host;
>         proxy_set_header X-Real-IP $remote_addr;
>         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
>         proxy_set_header Ssl-Offloaded "1";
>         proxy_set_header      X-Forwarded-Proto https;
>         proxy_set_header      X-Forwarded-Port 443;
>         #proxy_hide_header X-Varnish;
>         #proxy_hide_header Via;
>         proxy_set_header X-Forwarded-Proto $scheme;
>          try_files $uri $uri/ /index.php$is_args$args;
>     }
> 
> Any ideas. Thank you. :-)
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20191009/60e060f7/attachment.html>


More information about the varnish-misc mailing list