problem with setting http headers

sofatime

Well-Known Member
#1
Hi,

We are using lsws 4.2.6 Enterprise.

I would like to set http headers for caching (Cache-Control and Expires). This works perfectly for static objects. I am using the native configuration "Expires by Type" on server level.

Unfortunately it does not work for dynamically generated pages by php (we are using native processgroup php external app). On these pages the headers are not added. I have tried native configuration, Apache style configuration and .htaccess (allowoverride enabled).

What am I missing here?

Thanks
Daniel
 

sofatime

Well-Known Member
#3
Yes, that might work for our own applications, but I would like to set these headers for standard CMS like Wordpress or typo3. Of course it could be added somewhere there, but would be much easier in lsws.

We have an Apache/ColdFusion setup and there it's no problem to add headers also for ColdFusion pages. But then ColdFusion uses a different model to connect to Apache.

Is there any way to set these headers in lsws?

Thanks
Daniel
 

sofatime

Well-Known Member
#6
I could solve the problem. I added the following to "Apache Style configurations":

<FilesMatch "\.php$">
Header set Cache-Control max-age=3600
</FilesMatch>

That way the header "Cache-Control" is properly added to the response headers for php pages, while static objects still get the Cache-Control and Expires header defined by the lsws native "Expires By Type" configuration.
I don't get an Expires header for php pages, but I assume most modern browsers/proxies/CDNs understand Cache-Control by now.

A few additional notes:
- Without the FilesMatch directive lsws adds two Cache-Control headers: one from the native "Expires by Type" and one from the Apache style directive. Apache replaces the Cache-Control header, if "set" is used.
- I also tested the behaviour of Apache with mod_php: With this setup Expires directives also don't work for php pages, but Header directives work. So apparently Expires headers are added early in the request processing (before php), while Header directives come late (in both Apache and lsws).
- If your application sets additional headers like Pragma they can be removed by using "Header unset Pragma" (only tested in Apache).

Of course you need to be careful when setting Cache-Control max-age for dynamic pages. But as many websites only change seldom even if a CMS is used it might make sense to set Cache-Control, especially when used with a CDN in front.

Here's a great tutorial on cache headers:
http://www.mnot.net/cache_docs/

Daniel
 

sofatime

Well-Known Member
#8
I did some further tests and it seems that lsws does not support the following:

1) Header unset Cache-Control
2) env variables for Header: Header set Cache-Control no-cache env=NO_CACHE

Is this correct? If yes it would be great if you could implement it. This would allow me to set the cache headers also for CMS like Joomla which always set no-cache (using Header unset) and also to prevent double Cache-Control headers in the admin interfaces of the CMS.

Daniel
 
Top