Apache mod_expires

Moderator: cah

Post Reply
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

Apache mod_expires

Post by cah »

From "Apache Module mod_expires" page (http://httpd.apache.org/docs/2.2/mod/mod_expires.html), it says:

Code: Select all

ExpiresActive Directive
Description:	Enables generation of Expires headers
Syntax:    ExpiresActive On|Off
Context:   server config, virtual host, directory, .htaccess
Override:  Indexes
Status:    Extension
Module:    mod_expires
The following example shows:

Code: Select all

Example:

# enable expirations
ExpiresActive On
# expire GIF images after a month in the client's cache
ExpiresByType image/gif A2592000
# HTML documents are good for a week from the
# time they were changed
ExpiresByType text/html M604800 
I had similar settings in httpd.conf but my page never expires until I manually refresh the pages.

Code: Select all

ExpiresActive On
ExpiresByType text/html M1
I was wondering why.
I remember setting on RCCGNET and it is working perfectly.
I did a comparison on httpd to see if there's anything there. It doesn't even have mod_expires.c compiled in it. However, the configuration of virtual host section shows differences.

Code: Select all

<VirtualHost \
                        192.168.0.1:80 \
                        74.208.107.179:80 \
                        >
        ServerName jcsc.rccgcms.net
        UseCanonicalName Off
        DocumentRoot /var/www/vhosts/default/htdocs/JCSC
        ScriptAlias /cgi-bin/ "/var/www/vhosts/default/cgi-bin/"
        ErrorLog /var/log/httpd/error_log_jcsc
        CustomLog /var/log/httpd/access_log_jcsc combined
        <IfModule mod_ssl.c>
                SSLEngine off
        </IfModule>
        <Directory "/var/www/vhosts/default/cgi-bin/">
                AllowOverride None
                Options None
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/vhosts/default/htdocs/JCSC>
                AllowOverride All
                Options SymLinksIfOwnerMatch ExecCGI
                Order allow,deny
                Allow from all
        </Directory>
        ExpiresActive On
        ExpiresByType text/html M1
</VirtualHost>
Directory section is under virtual host.

I then checked httpd onhsiao.net. I found the folloiwing from 'httpd -L' list:

Code: Select all

ExpiresActive (mod_expires.c)
        Limited to 'on' or 'off'
        Allowed in *.conf anywhere and in .htaccess
        when AllowOverride includes Indexes
ExpiresByType (mod_expires.c)
        a MIME type followed by an expiry date code
        Allowed in *.conf anywhere and in .htaccess
        when AllowOverride includes Indexes
ExpiresDefault (mod_expires.c)
        an expiry date code
        Allowed in *.conf anywhere and in .htaccess
        when AllowOverride includes Indexes
It says these settings will work "only" when AllowOverride includes "Indexes".

I went back to the above mod_expires page and checked again. It does have "Override: Indexes" in it.
I clicked on "Override" link and found:

Code: Select all

Override

This directive attribute indicates which configuration override must be active in order for the directive to be processed when it appears in a .htaccess file. If the directive's context doesn't permit it to appear in .htaccess files, then no context will be listed.

Overrides are activated by the AllowOverride directive, and apply to a particular scope (such as a directory) and all descendants, unless further modified by other AllowOverride directives at lower levels. The documentation for that directive also lists the possible override names available.
I never put AllowOverride Indexes under virtual host section. That may be the reason why it didn't work.
Here is the modified config for my virtual host:

Code: Select all

<VirtualHost 192.168.1.225:80>
    ServerAdmin cah@hsiao.net
    DocumentRoot /export/home/www/html/cah
    ServerName chang-an.hsiao.net
    ServerAlias cah.hsiao.net
    ErrorLog /export/home/cah/logs/error_log_an
    CustomLog /export/home/cah/logs/access_log_an combined
    HostnameLookups on
    <Directory "/export/home/www/html/cah">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
    </Directory>
    ExpiresActive On
    ExpiresByType text/html M1
    AddHandler server-parsed .shtml
</VirtualHost>
I added the same config change to Chia-Wei's virtual host section and restarted Apache.
The pages seem to change now. More testing may be needed to call the conclusion.

After trying more tests, it didn't seem to help.
The page didn't show the latest page until it's manually refreshed...................
CAH, The Great
Post Reply