In my previous post, you saw some Apache configuration tips to optimize your Apache web server in Ubuntu. Now I am going to show you more Apache performance tuning tips and tricks. This will improve the overall performance of your Apache web server.

Enable mod_deflate Compression

Mod_deflate is an Apache module that allows output from your Apache server to be compressed before being sent to the browser. This will reduce the size of the content that is required to be sent and will decrease the time and the amount of data transmitted to the browser. Mod_deflate module uses gzip compression to compress data, text, HTML, or XML files to approximately 30% of their original sizes.

In Ubuntu 14.04, by default, the mod_deflate module is included and enabled in Apache.

To confirm this, run the following command:

sudoapachectl-t-D DUMP_MODULES |grep deflate

You should see deflate_module (shared) if mod_deflate is enabled.

By default, the gzip compression level is 9. You can set the gzip compression level from 1 to 9 as necessary.

For example, you can set the gzip compression level to 8 by editing the “/etc/apache2/mods-enabled/deflate.conf” file.

sudonano/etc/apache2/mods-enabled/deflate.conf

Add the following line:

DeflateCompressionLevel 8

Save the file and restart Apache.

sudo/etc/init.d/apache2 restart

Set Up Varnish Cache

Varnish cache is an HTTP accelerator and reverse proxy for speeding up an Apache server. It is used to speed up a website by storing a copy of a page served by an Apache web server. It makes the website load faster because it stores the content in RAM.

Note: the following is only a simple example of how to install, configure and start Varnish with an Apache web server. In most cases, you will have to configure it further to suit your own needs.

Install Varnish:

First, you need to add the varnish repository to install varnish on your system.

Save the file and open the “default.vcl” file. This file tells varnish to look for the server content.

sudonano/etc/varnish/default.vcl

Now tell varnish to get the content on port 8080.

backend default {
.host = "127.0.0.1";
.port = "8080";
}

By default, Apache listens on port 80; you need to change this port to 8080.

You can change the Apache listening port from 80 to 8080 by editing the ports.conf file.

sudonano/etc/apache2/ports.conf

Change the value from 80 to 8080.

Listen 8080

Save the file and restart Apache and varnish.

sudo/etc/init.d/apache2 restart
sudo/etc/init.d/varnish restart

Now you can now check the status of varnish by running

sudo varnishstat

Set Up APC

APC (Alternative PHP Cache) is a free open-source opcode caching plugin for PHP that can help speed up your site. It caches the output of the PHP bytecode compiler in shared memory; this will reduce parsing and disk I/O overhead for later requests.

Now open that file in the browser. You should see APC enabled as shown in the below image.

Conclusion

Now, you have enough knowledge to tune up an Apache web server for the best performance. You can also experiment with various available options and measure the web server performance by using tools like ab and httperf. Feel free to comment if you have any questions.

3 comments

It has something to do with the “Disable Old Protocol (HTTP 1.0)” section. I removed the lines RewriteEngine On RewriteCond %{THE_REQUEST} !HTTP/1\.1$ RewriteRule .* – [F] from apache2.conf file and now it’s working.

Is there a way to get this security tweak working correctly with Varnish?