Configure Caching in Apache and IIS 8 Part 2 – Web Server Configuration

By | August 2, 2017

Caching reduces load time improving web application performance

In the first part of this article we discussed the tools you can use to check the performance of your blog or hosted web site both to obtain a base line and also to measure the improvements the QualTech Custom Java Development Services | QualTech360Developmentadjustments we’ll discuss are bringing to your web site.

In this second part we are going over the changes you can make to the servers and to the application and how you can go about making those changes in order to take advantage the caching features built in the web servers and browsers in order to get the most improvement.

The changes we’ll be discussing have to be made in 2 different areas and complement each other. Cache configuration of the web servers side and file minimization and image compression on the application side.

Web server cache configuration

Configuring cache in the Apache Server

We are going to start by configuring caching on an Apache web server running on a CentOs Linux server. This can be the case when you are hosting a site like a WordPress blog for example or a custom developed Java cross platform application.

QualTech Linux Infrastructure as a Service | QualTech360InfrastructureIf you would like to check the version of  the CentOs OS you are running you can type the following command in the command prompt:

cat /etc/redhat-release

You would get a response similar to the picture to the left which shows that one server is running CentOs version 7 and the other is running CentoOs version 6.6. In our cloud infrastructure we are only deploying CentOs 7 but our blog is running on a CentOs 6.

The next thing we need to do is add the cache configuration to Apache’s configuration file. You should find the configuration file under /usr/local/httpd/conf. Apache’s configuration file is named httpd.conf.

In a standard deployment of CentOs 7 you are likely to find the Apache folder under /etc/httpd/conf.

When it comes to making changes to Apache’s configuration file it’s usually a good idea to put those changes in a custom .conf file as for example mycache.conf. If you open httpd.conf and scroll all the way to the end you’ll see that when Apache starts it will load any .conf file located in the /etc/httpd/conf.d folder. That’s done because at the end of the httpd.conf you’ll find the lineQualtech Cloud Hosted Infrastructure for Linux | QualTech360Infrastructure

IncludeOptional conf.d/*.conf

This is more important if you are hosting the site in a vps on an ISP where you use cPanel and WHM to manage the vm. Any changes you make manually to the httpd.conf they will be overwritten next time you make a change using those tools. In this case you should go to the Server Configuration in WHM and find out which .conf file is being loaded by the httpd.conf file. You should make your changes in that file.

Once you figure out where you should add the settings for caching add the following to the .conf file:

<IfModule mod_expires.c>
ExpiresActive on

ExpiresByType image/jpg “access plus 60 days”
ExpiresByType image/png “access plus 60 days”
ExpiresByType image/gif “access plus 60 days”
ExpiresByType image/jpeg “access plus 60 days”

ExpiresByType text/css “access plus 1 days”

ExpiresByType image/x-icon “access plus 1 month”

ExpiresByType application/pdf “access plus 1 month”
ExpiresByType audio/x-wav “access plus 1 month”
ExpiresByType audio/mpeg “access plus 1 month”
ExpiresByType video/mpeg “access plus 1 month”
ExpiresByType video/mp4 “access plus 1 month”
ExpiresByType video/quicktime “access plus 1 month”
ExpiresByType video/x-ms-wmv “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access 1 month”

ExpiresByType text/javascript “access plus 1 week”
ExpiresByType application/x-javascript “access plus 1 week”
ExpiresByType application/javascript “access plus 1 week”
</IfModule>

These entries configure how each of those file types should be cached and how long they should live on the browser side. If these files are already on the browser side when a page is loaded then the browser just loads them from the local cache reducing the load time.

You can find detailed information here. After you complete these changes don’t forget to restart Apache:


service httpd restart or systemctl restart httpd

Configuring cache in IIS

If instead you are running your web site in an IIS server on Windows 2012 this is how you make similar configuration changes.QualTech Custom .Net Development | QualTech360Development

Open Internet Information Services Manager and select the web site you want to configure. From the pane on the right double click Output Caching. In the Actions pane click Add the entries for the file types and expiration as it shows in the picture below.

QualTech Custom Development for .Net | QualTech360DevelopmentHere also don’t forget to reset IIS after you are done with all the changes.

If you have any questions, comments or anything you would like to add to this article feel free to leave a comment or email us at info@qualtechsoftware.com

#QualTech360Care, #QualTech360Development, #QualTech360Solutions #QualTech360Java #QualTech360.Net

 

One thought on “Configure Caching in Apache and IIS 8 Part 2 – Web Server Configuration

  1. Pingback: Configure Caching in Apache and IIS 8 Part 3 – Minify and Compress | QualTech Software

Leave a Reply