[nginx] Examples of using expire

Deebs

New Member
Staff member
Teczone runs under nginx which in turn is using php-fpm. The following entries are snippets from the configuration file where I have used the expires command.

Code:
        # Let's set the cache on certain file extensions and not log access to them
        location ~* ^.+\.(css|js)$ {
            access_log off;
            expires 1d; 
        }

        # Let's set the cache on image file extensions and not log access to them       
        location ~* ^.+\.(gif|jpg|jpeg|png)$ {
            access_log off;
            expires 7d;
        }
The above two locations basically do the following:
  1. Do not log any access attempt (successful or not) in the log file.
  2. For any file ending in .css or .js set the expiry date to be 1 day in the future.
  3. For any file ending in .gif, .jpg, .jpeg or .png set the expiry date to be 7 days in the future.
 

Zarjazz

New Member
You can do something similar using lighttpd:

Code:
$HTTP["url"] =~ "\.(css|js|gif|jpe?g|png)$" {
  expire.url = ( "" => "access plus 1 days" )
}
 
Top Bottom