problem with setting http headers

Discussion in 'Install/Configuration' started by sofatime, Jan 10, 2014.

  1. sofatime

    sofatime Well-Known Member


    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?

  2. NiteWave

    NiteWave Administrator

  3. sofatime

    sofatime Well-Known Member

    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?

  4. NiteWave

    NiteWave Administrator

    can you give a example how to add headers to ColdFusion in apache ?
    so make the issue more clear.
  5. sofatime

    sofatime Well-Known Member


    ExpiresActive On
    ExpiresByType text/html "access plus 1 day"

  6. sofatime

    sofatime Well-Known Member

    I could solve the problem. I added the following to "Apache Style configurations":

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

    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:

  7. NiteWave

    NiteWave Administrator

    good research work done, thanks. will benefit for other users who search to here.

    lsws may improve
    function in future release.
  8. sofatime

    sofatime Well-Known Member

    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.

  9. NiteWave

    NiteWave Administrator

    yes. looks same test result as mine

    this 2 looks most useful ones than others(within mod_headers)

Share This Page