Page 1 of 1

Setting header expiration for files ?

Posted: Mon Jun 03, 2019 1:17 pm
by Spheerys
Hi,

I'm a web integrator and I'm using VestaCP to host my websites.
When I'm changing a CSS file with FTP or SSH, the new file is not reload immediatly, but after a while.
It's very anoying during the integration time :)
I thaught it could be caused because of nginx/apache header expiration setting but I'm not sure 100%
After web research, I have set theses lines on my local .htaccess file :

Code: Select all

<FilesMatch "\.(?i:css|js)$">
  <IfModule mod_headers.c>
    Header set Cache-Control "max-age=0, public, must-revalidate"
  </IfModule>
</FilesMatch>
... but nothing change.
The headers module is correctly set :

Code: Select all

 # a2enmod headers
Module headers already enabled
Do you know where the problem come from, or what I am doing wrong ?

Thanks !

My configuration is Debian 9 with Nginx+Apache.

Re: Setting header expiration for files ?

Posted: Mon Jun 03, 2019 2:00 pm
by grayfolk
You should setup headers in nginx config, not in apache.

Re: Setting header expiration for files ?

Posted: Mon Jun 03, 2019 2:23 pm
by Spheerys
OK but which file to edit ?

Re: Setting header expiration for files ?

Posted: Tue Jun 04, 2019 11:50 am
by Spheerys
On VestaCp Nginx's config, I have found this line :

Code: Select all

    # File cache settings
    open_file_cache          max=10000 inactive=30s;
I suppose a value to 2s will solve my issue but I wonder if there is not a website specific setting instead of a server setting which overload the whole server load

Re: Setting header expiration for files ?

Posted: Thu Jun 06, 2019 3:06 pm
by Spheerys
I have found the way to edit only a particular website, but this modification will disappear after a v-rebuild-web-domain :
  • edit the file /home/USER/conf/web/domain.tld.nginx.conf
  • remove "css|" (or all other filetypes) on the line "location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico...."
  • service nginx restart
It's enough for me, but if someone know how to make this change definitive, it could be usefull :)

Re: Setting header expiration for files ?

Posted: Thu Jun 06, 2019 4:16 pm
by grayfolk
Spheerys wrote:
Thu Jun 06, 2019 3:06 pm

remove "css|" (or all other filetypes) on the line "location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico...."
Good way for development, very bad for production sites.

Re: Setting header expiration for files ?

Posted: Wed Jun 03, 2020 5:06 pm
by AlektroNik
grayfolk wrote:
Mon Jun 03, 2019 2:00 pm
You should setup headers in nginx config, not in apache.
Hi.
And there is the option of using .htaccess?
If different sites need to use different settings what to do?
Use templates with nginx is not convenient, it is necessary for each site template to create.
Maybe I can use .user.ini?

Re: Setting header expiration for files ?

Posted: Wed Jun 03, 2020 5:13 pm
by grayfolk
AlektroNik wrote:
Wed Jun 03, 2020 5:06 pm

Use templates with nginx is not convenient, it is necessary for each site template to create.
This is best way. Because, what reason to install nginx over apache?
If you dont have nginx - use .htaccess.

Re: Setting header expiration for files ?

Posted: Wed Jun 03, 2020 5:37 pm
by AlektroNik
grayfolk wrote:
Wed Jun 03, 2020 5:13 pm
what reason to install nginx over apache?
NGINX is faster gives the statics :)
I can't believe NGINX can not proxy headers from .htaccess. I would like to believe that I just don't know how to cook it :)
grayfolk wrote:
Wed Jun 03, 2020 5:13 pm
If you dont have nginx - use .htaccess.
If indeed the only more or less acceptable option is to use templates with NGINX, then probably will consider using only Apache. :(

Thank you very much.

Re: Setting header expiration for files ?

Posted: Wed Jun 03, 2020 6:00 pm
by grayfolk
AlektroNik wrote:
Wed Jun 03, 2020 5:37 pm

NGINX is faster gives the statics :)
Right! And this is reason to use it for serve static files.
AlektroNik wrote:
Wed Jun 03, 2020 5:37 pm

I can't believe NGINX can not proxy headers from .htaccess. I would like to believe that I just don't know how to cook it :)
May be can - i dont understand, but in this case we lost nginx speed )