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.

Limit Apache only listen to IPv4 address

Answer:

Apache httpd web server might listen IPv6 address if your system support IPv6.

To disable IPv6 supprt, add the following lines to the Apache configuration (httpd.conf)

# Listen 80
Listen 0.0.0.0:80 # New value

Restart Apache to take effect

# apachectl -k graceful

Enable Expire header in Nginx

Answer:

Enabling Expire header for static contents is useful to reduce the loading of your web server.

If you are using nginx, it is easy by adding the following lines in your nginx.conf

location ~* \.(ico|css|js|gif|jpe?g|png)$ {
    expires max;
}

So all files with the above extensions will be delivered with the maximum expire header.

If you want user to update the cached contents, make sure you have change the path (i.e. rename) of these resources.

Block request by user agent in Apache

Answer:

If you want to block request to your web site, by user agent string, you can change by editing the Apache's configuration.

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

RewriteCond %{HTTP_USER_AGENT} googlebot
RewriteRule . - [F,L]

The above config block all requests from Google's Bot. (Make sure mod_rewrite is installed and enabled)

Also, remember to restart Apache to take effect

# apachectl -k graceful

Turn off directory listing in Apache

Answer:

If you web site's directory without a valid default index page, e.g. index.html, Apache might list all files inside the directory. If you want to turn off, do the following.

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

Options All -Indexes

Restart Apache to take effect

# apachectl -k graceful

Change the access file name (i.e. .htaccess) in Apache

Answer:

If you have not set the AllowOverride to None in your Apache's configuration, Apache will read the file .htaccess on every request. If you want to use a file name other than .htaccess, you can set using the AccessFileName directive

AccessFileName .acl

Then Apache will read the file .acl instead, remember to restart your Apache to take effect.