Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Feb 122010
 

Turn on expire headers in Apache

Answer:

By turning on the expire headers, browser will cache the files serving from Apache more aggressively, so as to reduce traffic loading to the Apache web server.

Steps:

Add the following lines to the Apache configuration (httpd.conf)

<IfModule mod_expires.c>
    ExpiresActive On

    # Cache all files for 2 weeks after access (A).
    ExpiresDefault A1209600
    
    # Do not cache dynamically generated pages.
    ExpiresByType text/html A1
</IfModule>

Restart Apache to take effect

# apachectl -k graceful

Assume the module mod_expires is enabled

Feb 092010
 

How to define variable in nginx

Answer:

nginx provided a very simple way to define custom variable, which can provide a very flexible way to control your web server.

E.g.

set $foo bar; 

if ($foo ~ bar) {
    # do something  
}

Feb 092010
 

Add custom HTTP header by nginx

Answer:

To inject custom HTTP header into the HTTP response, is very easy with nginx.

Add the following line into the configuration (add into the location you need):

E.g.

location / {
    add_header Foo Bar;
} 
Feb 042010
 

Turn on content compression in Apache

Answer:

By turning on content compression in Apache, content's transfer size can be reduced for users and hence a faster loading time. However, not all content types can be compressed, e.g. images, videos, we usually only compress text content types, e.g. html, xml, css & js.

Steps:

Add the following lines to the Apache configuration (httpd.conf)

<IfModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/xml application/xml application/javascript application/json text/css text/plain
    header set Vary Accept-Encoding

    # Don't compress images - Important for IE caching bug
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    header unset Vary env=dont-vary

</IfModule>

Restart Apache to take effect

# apachectl -k graceful

Assume the module mod_deflate is enabled

Jan 152010
 

How to enable Server Side Includes (SSI) ?

Answer:

Pick either one of the following method and add the following lines to Apache configuration (httpd.conf).

1. Enable SSI on files with extension .shtml

AddType text/html .shtml
AddHandler server-parsed .shtml

2. Enable SSI on files if they have the user-execute bit set

XBitHack on

Reference: http://httpd.apache.org/docs/1.3/mod/mod_include.html