<div id="geary-body" dir="auto"><div>Hi,</div><div><br></div><div>I don't think it's related to Varnish.</div><div><br></div><div>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.</div><div>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)</div></div><div id="geary-quote" dir="auto"><br>On Tue, Oct 8, 2019 at 4:17 PM, Akshay Sulakhe <kernelfreak@gmail.com> wrote:<br><blockquote type="cite">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<p>Hello friends,<br>
</p>
<p>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. <br>
</p>
<p>Error log :</p>
<pre class="default prettyprint prettyprinted" style=""><code><span class="pln">pub</span><span class="pun">/</span><span class="kwd">static</span><span class="pun">/</span><span class="pln">version123456</span><span class="pun">/</span><span class="pln">frontend</span><span class="pun">/</span><span class="pln">company</span><span class="pun">/</span><span class="kwd">default</span><span class="pun">/</span><span class="pln">de_DE</span><span class="pun">/</span><span class="pln">css</span><span class="pun">/</span><span class="pln">styles</span><span class="pun">-</span><span class="lit">1.min</span><span class="pun">.</span><span class="pln">css was blocked due to MIME type </span><span class="pun">(</span><span class="str">"text/html"</span><span class="pun">)</span><span class="pln"> mismatch </span><span class="pun">(</span><span class="pln">X</span><span class="pun">-</span><span class="typ">Content</span><span class="pun">-</span><span class="typ">Type</span><span class="
pun">-</span><span class="typ">Options</span><span class="pun">:</span><span class="pln"> nosniff</span><span class="pun">)
</span></code></pre>
<p>We don't have no-sniff added in our Nginx configuration.</p>
<p>Varnish config :</p>
<p>
default.vcl <br>
</p>
<pre class="default prettyprint prettyprinted" style=""><code><span class="pln">backend server1c </span><span class="pun">{</span><span class="pln">
</span><span class="pun">.</span><span class="pln">host </span><span class="pun">=</span><span class="pln"> </span><span class="str">"IP1"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">port </span><span class="pun">=</span><span class="pln"> </span><span class="str">"80"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">probe </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="pun">.</span><span class="pln">url </span><span class="pun">=</span><span class="pln"> </span><span class="str">"/balancer.html"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">timeout </span><span class="pun">=</span><span class="pln"> </span><span class="lit">500s</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">interval </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5s</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">window </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">threshold </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
backend server1b </span><span class="pun">{</span><span class="pln">
</span><span class="pun">.</span><span class="pln">host </span><span class="pun">=</span><span class="pln"> </span><span class="str">"IP2"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">port </span><span class="pun">=</span><span class="pln"> </span><span class="str">"80"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">probe </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="pun">.</span><span class="pln">url </span><span class="pun">=</span><span class="pln"> </span><span class="str">"/balancer.html"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">timeout </span><span class="pun">=</span><span class="pln"> </span><span class="lit">500s</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">interval </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5s</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">window </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">threshold </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
backend server1a </span><span class="pun">{</span><span class="pln">
</span><span class="pun">.</span><span class="pln">host </span><span class="pun">=</span><span class="pln"> </span><span class="str">"IP3"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">port </span><span class="pun">=</span><span class="pln"> </span><span class="str">"80"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">probe </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="pun">.</span><span class="pln">url </span><span class="pun">=</span><span class="pln"> </span><span class="str">"/pub/balancer.html"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">timeout </span><span class="pun">=</span><span class="pln"> </span><span class="lit">500s</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">interval </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5s</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">window </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span><span class="pln">
</span><span class="pun">.</span><span class="pln">threshold </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">sub</span><span class="pln"> vcl_recv </span><span class="pun">{</span><span class="pln">
</span><span class="com"># Happens before we check if we have this in cache already.</span><span class="pln">
</span><span class="com">#</span><span class="pln">
</span><span class="com"># Typically you clean up the request here, removing cookies you don't need,</span><span class="pln">
</span><span class="com"># rewriting the request, etc.</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/lazyload/prices/load/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/roobeo_config/store/changemode/mode/0"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/roobeo_config/store/changemode/mode/1"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/rest/default/V1/carts/mine/estimate-shipping-methods"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/lazywishlist/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/index.php/rest/V1/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/customer/account/createpassword/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/customer/account/resetpasswordpost/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/roobeo_shipping/zipcode/validate/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/roobeo_shipping/zipcode/save/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">req</span><span class="pun">.</span><span class="pln">url </span><span class="pun">==</span><span class="pln"> </span><span class="str">"/roobeo_shipping"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">pass</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">sub</span><span class="pln"> vcl_init </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">new</span><span class="pln"> bar </span><span class="pun">=</span><span class="pln"> directors</span><span class="pun">.</span><span class="pln">round_robin</span><span class="pun">();</span><span class="pln">
bar</span><span class="pun">.</span><span class="pln">add_backend</span><span class="pun">(</span><span class="pln">server1a</span><span class="pun">);</span><span class="pln">
bar</span><span class="pun">.</span><span class="pln">add_backend</span><span class="pun">(</span><span class="pln">server1b</span><span class="pun">);</span><span class="pln">
bar</span><span class="pun">.</span><span class="pln">add_backend</span><span class="pun">(</span><span class="pln">server1c</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span></code></pre>
<p><br>
</p>
<p>Nginx config :</p>
<pre class="default prettyprint prettyprinted" style=""><code><span class="pln"> location </span><span class="pun">/</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
proxy_pass http</span><span class="pun">:</span><span class="com">//VARNISH_IP:80;</span><span class="pln">
proxy_set_header </span><span class="typ">Host</span><span class="pln"> $http_host</span><span class="pun">;</span><span class="pln">
proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Host</span><span class="pln"> $http_host</span><span class="pun">;</span><span class="pln">
proxy_set_header X</span><span class="pun">-</span><span class="typ">Real</span><span class="pun">-</span><span class="pln">IP $remote_addr</span><span class="pun">;</span><span class="pln">
proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">For</span><span class="pln"> $proxy_add_x_forwarded_for</span><span class="pun">;</span><span class="pln">
proxy_set_header </span><span class="typ">Ssl</span><span class="pun">-</span><span class="typ">Offloaded</span><span class="pln"> </span><span class="str">"1"</span><span class="pun">;</span><span class="pln">
proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Proto</span><span class="pln"> https</span><span class="pun">;</span><span class="pln">
proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Port</span><span class="pln"> </span><span class="lit">443</span><span class="pun">;</span><span class="pln">
</span><span class="com">#proxy_hide_header X-Varnish;</span><span class="pln">
</span><span class="com">#proxy_hide_header Via;</span><span class="pln">
proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Proto</span><span class="pln"> $scheme</span><span class="pun">;</span><span class="pln">
try_files $uri $uri</span><span class="pun">/</span><span class="pln"> </span><span class="pun">/</span><span class="pln">index</span><span class="pun">.</span><span class="pln">php$is_args$args</span><span class="pun">;</span><span class="pln">
</span><span class="pun">}
Any ideas. Thank you. :-)
</span></code></pre>
<p><br>
</p>
<pre class="default prettyprint prettyprinted" style=""><code><span class="pun"></span></code></pre>
</blockquote></div>