Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

Nginx: Can't set Cache-Control header max-age to 0

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
2 posts • Page 1 of 1
michaelb
Posts: 2
Joined: Sat Sep 29, 2018 8:33 am

Os: Ubuntu 16x
Web: apache + nginx
Nginx: Can't set Cache-Control header max-age to 0
  • Quote

Post by michaelb » Sat Sep 29, 2018 9:37 am

I'm still pretty new to Vesta and having been battling with a caching issue for the last few days:

I'm hosting a PWA and the service worker file must not be cached. I'm using Apache and Nginx as reverse proxy. Server is running Ubuntu 18.04 and using the latest VestaCP

I've set up the domain to use custom templates based on the default templates and including the following:

../templates/web/apache2/pwa.stpl and ../templates/web/apache2/pwa.tpl

Code: Select all

<Files "service-worker.js">
    FileETag None
    Header unset ETag
    Header set Cache-Control "max-age=0, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set expires "Wed, 11 Jan 1984 05:00:00 GMT"
</Files>
and ../templates/web/nginx/pwa.stpl and ../templates/web/nginx/pwa.tpl

Code: Select all

location service-worker.js {
    add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    expires off;
    proxy_no_cache 1;
}
but when I view the headers on the service worker file, it still reads:

Code: Select all

Accept-Ranges: bytes
Cache-Control: max-age=315360000                          <-------
Connection: keep-alive
Content-Length: 964
Content-Type: application/javascript
Date: Sat, 29 Sep 2018 09:34:03 GMT
ETag: "5baf10c0-3c4"
Expires: Thu, 31 Dec 2037 23:55:55 GMT                   <--------
Last-Modified: Sat, 29 Sep 2018 05:42:24 GMT
Server: nginx
Would appreciate any ideas - thanks
Top

michaelb
Posts: 2
Joined: Sat Sep 29, 2018 8:33 am

Os: Ubuntu 16x
Web: apache + nginx
Re: Nginx: Can't set Cache-Control header max-age to 0
  • Quote

Post by michaelb » Sat Sep 29, 2018 7:32 pm

Making some progress:

The file that needs to be edited is /home/myuser/conf/web/mydomain.nginx.ssl.conf and the location snippet relating to the service-worker.js file must go ABOVE the more general location clause (and must include the root value or else it will result in a 404) as follows:

Code: Select all

location / {
        proxy_pass      https://x.x.x.x:8443;
        location ~ (index.html|service-worker.js)$ {
            root           /home/myuser/web/mydomain/public_html;
            add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
	    expires off;
	}
	location ~* ^.+\.(jpg|jpeg|gif|png|ico|svg|css|zip|tgz|gz|rar|bz2|exe|pdf|doc|xls|ppt|txt|odt|ods|odp|odf|tar|bmp|rtf|js|mp3|avi|mpeg|flv|html|htm)$ {
            root           /home/myuser/web/mydomain/public_html;
            access_log     /var/log/apache2/domains/mydomain.log combined;
            access_log     /var/log/apache2/domains/mydomain.bytes bytes;
	    expires        max;
            try_files      $uri @fallback;
        }
    }
Top


Post Reply
  • Print view

2 posts • Page 1 of 1

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

cron

Login  •  Register

I forgot my password