Before we get to browser caching, let’s answer the question: What is Caching? Visit our What is Caching? tutorial if you don’t already know what caching is!
- These instructions are intended specifically for configuring Apache 2 to control browser caching.
- I’ll be working from a Liquid Web Core Managed CentOS 7 server, and I’ll be logged in as root.
Step #1: Verify Modules
Apache must be configured with the appropriate modules to leverage browser caching.
Let’s check for mod_expires (expires_module) first:
apachectl -M | grep expires
… should return:
Then let’s check for mod_headers (headers_module):
apachectl -M | grep headers
… should return:
Step #2: Examples of Directives
This code can be placed in the .htaccess files for specific directories, or in your root web directory, but we suggest placing it in your httpd.conf.
# Turn on the module.
# Set the default expiry times.
ExpiresDefault "access plus 2 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "now plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 600 seconds"
- The default expiration (ExpiresDefault) is set to 2 days.
- Images expire after 1 month.
- HTML expires after 10 minutes (600 seconds).
Step #3: Implement Directives
The above directives can be implemented easily. If you’re not already, SSH into your server as root. Then we’ll use vim to edit the httpd.conf file. For a refresher on editing files with vim see: New User Tutorial: Overview of the Vim Text Editor. If you’re using Liquid Web’s CentOS 7 Core Managed image then the following command already uses the correct location:
Find a section that looks like this:
# Further relax access to the default document root:
… the section above (in this case) is the default document root. Add the expiration directives between <Directory “/var/www/html”> and </Directory>.
Then restart Apache 2!
systemctl restart httpd
Full details for mod_expires can be found in the Apache Documentation.
- These instructions are intended specifically for solving the error: No matching DirectoryIndex (index.html) found.
- I’ll be working from both Liquid Web Core Managed CentOS 6 and CentOS 7 servers, and I’ll be logged in as root.
Continue reading “Apache Error: No matching DirectoryIndex (index.html) found [SOLVED]”
If you are used to administering Apache on a cPanel server, administering the faster Litespeed webserver is not that much different. Litespeed transparently takes over for Apache; any configuration changes that you would normally make in an Apache configuration file or .htaccess files is still made in those files. In fact, once Litespeed is installed you can administer your cPanel server like you normally would. The few changes you would want to make to Litespeed directly can be done through your server’s Web Host Manager (WHM).
Continue reading “Administering LiteSpeed Web Server in cPanel”
Load balancing is the distribution of a workload across many nodes. In the webhosting industry, it is typically used for balancing http traffic over multiple servers acting together as a web front-end. For the sake of this article, we will focus on the balancing of HTTP and HTTPS traffic through a Zeus Load Balancer.
Continue reading “Understanding Load Balancing”
‘Premature end of script headers’ can be an extremely vague error that leads to some headaches. Here are some suggestions that might help you fix the problem.
Continue reading “Apache Error: Premature End of Script Headers”
Using Softaculous, a new CMS(Content Management System) such as WordPress, Joomla, or Mambo has been installed on your website. It does not matter which CMS is installed, they all need to be able to write files on the server. However, they could show “permission denied” errors during the first-time setup or the first time an upload is attempted via their built-in web interface. This can happen when using DSO or CGI as the PHP handler. With either handler, php scripts by default run as the Apache user “nobody”, and the webserver software (usually Apache) needs to have write access to a user’s files to avoid this error.
Continue reading “File Upload Problems”
The default Apache settings that cPanel sets upon install are definitely something that can be improved on. With a few small tweaks, the efficiency with which Apache runs with can be greatly improved.
Please noted: This article assumes that you are using a Linux server running Apache and cPanel or Plesk, and that you are familiar with editing files from the command line.
Continue reading “Apache Optimization”