Nginx

How to Install ‘Varnish’ (HTTP Accelerator) and Perform Load Testing Using Apache Benchmark

How to Install &-8216;Varnish&-8217; (HTTP Accelerator) and Perform Load Testing Using Apache Benchmark &-8211; this Article or News was published on this date:2019-05-28 18:51:57 kindly share it with friends if you find it helpful

Think for a moment about what happened when you browsed to the current page. You either clicked on a link that you received via a newsletter, or on the link on the homepage of sfnews.com, and then were taken to this article.

In few words, you (or actually your browser) sent a HTTP request to the web server that hosts this site, and the server sent back a HTTP response.

Install Varnish Cache for Apache and NginxInstall Varnish Cache for Apache and Nginx

As simple as this sounds, this process involves much more than that. A lot of processing had to be done server-side in order to present the nicely formatted page that you can see with all the resources in it – static and dynamic. Without digging much deeper, you can imagine that if the web server has to respond to many requests like this simultaneously (make it only a few hundred for starters), it can either bring itself or the whole system to a crawl before long.

And that is where Varnish, a high-performance HTTP accelerator and reverse proxy, can save the day. In this article I’ll explain how to install and use Varnish as a front-end to Apache or Nginx in order to cache HTTP responses faster and without placing further load on the web server.

However, since Varnish normally stores its cache in memory instead of on disk we will need to be careful and limit the RAM space allocated for caching. We will discuss how to do this in a minute.

Install Varnish Cache for Apache and NginxHow Varnish Works

How Varnish Works

Installing Varnish

This post assumes that you have installed a LAMP or LEMP server. If not, please install one of those stacks before proceeding.

  1. Install LAMP in CentOS 7
  2. Install LEMP in CentOS 7

The official documentation recommends installing Varnish from the developer’s own repository because they always provide the latest version. You can also choose to install the package from your distribution’s official repositories, although it may be a little outdated.

Also, please note that the project’s repositories only provide support for 64-bit systems, whereas for 32-bit machines you’ll have to resort to your distribution’s officially maintained repositories.

In this article we will install Varnish from the repositories officially supported by each distribution. The main reason behind this decision is to provide uniformity in the installation method and ensure automatic dependency resolution for all architectures.

On Debian and Ubuntu
- aptitude update && aptitude install varnish 	[preface each command with sudo on Ubuntu]
On RHEL, CentOS and Fedora

For CentOS and RHEL, you will need to enable the EPEL repository before installing Varnish.

- yum update && yum install varnish 

If the installation completes successfully, you will have one of the following versions depending on your distribution:

  1. Debian: 3.0.2-2+deb7u1
  2. Ubuntu: 3.0.2-1
  3. Fedora, CentOS, and RHEL (the version is the same as Varnish is available from the EPEL repository): v4.0.2

Finally, you need to start Varnish manually if the installation process didn’t do it for you, and enable it to start on boot.

On Debian, Ubuntu, CentOS/RHEL 6.x and Fedora 15-20
- service varnish start
- service varnish status
- chkconfig --level 345 varnish on
On CentOS/RHEL 7.x and Fedora 21
- systemctl start varnish
- systemctl status varnish
- system enable varnish

Install Mod_Pagespeed to Speed Up Apache and Nginx Performance Upto 10x

Install Mod_Pagespeed to Speed Up Apache and Nginx Performance Upto 10x &-8211; this Article or News was published on this date:2019-05-28 17:39:23 kindly share it with friends if you find it helpful

This is our on going series on Apache optimization and performance tuning, here we are introducing a new Google‘s product called mod_pagespeed module for Apache or Nginx that makes the web site load much faster than ever.

Install Mod_Pagespeed for Apache and NginxInstall Mod_Pagespeed for Apache and Nginx

Install Mod_Pagespeed for Apache and Nginx

I have personally tested this module on our Live (sfnews.com) server and results are amazing, now the site loads much faster than before. I recommend you all to install it and see the results.

Don’t Miss: 5 Tips to Boost the Performance of Your Apache Web Server

In this article we will show you how to install and configure Google‘s mod_pagespeed module for Apache and Nginx web servers in RHEL/CentOS/Fedora and Debian/Ubuntu systems using official binary packages, so that your system will get regular updates automatically and stays up to date.

What Is Mod_PageSpeed

mod_pagespeed is an open source module for Apache and Nginx web server that automatically optimize Web Pages to improve better performance while serving web pages using HTTP Server.

It has several filters that automatically optimize files like HTML, CSS, JavaScript, JPEG, PNG and other resources.

mod_pagespeed is developed on PageSpeed Optimization Libraries, deployed over 100K+ websites, and provided by most popular CDN and Hosting providers such as GoDaddy, EdgeCast, DreamHost and few to name.

It offers more than 40+ optimization filters, which includes:

  1. Image optimization, compression, and resizing
  2. CSS & JavaScript concatenation, minification, and inlining
  3. Cache extension, domain sharding and rewriting
  4. Deferred loading of JS and image resources
  5. and many others…

Currently mod_pagespeed module supported Linux platforms are RHEL/CentOS/Fedora and Debian/Ubuntu for 32 bit and 64 bit distributions.

Install mod_pagespeed for Apache and Nginx on RHEL/CentOS/Fedora and Debian/Ubuntu

Installing Mod_Pagespeed Module in Linux

As I discussed above that we are using Google‘s official binary packages to install it for future updates, so let’s go ahead and install it on your systems based on your OS architecture.

On RHEL/CentOS and Fedora

----------- On 32-bit Systems -----------------
- wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm
- yum install at   [- if you don't already have 'at' installed]
- rpm -Uvh mod-pagespeed-stable_current_i386.rpm

----------- On 64-bit Systems -----------------
- wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
- yum install at   [- if you don't already have 'at' installed]
- rpm -Uvh mod-pagespeed-stable_current_x86_64.rpm

On Debian and Ubuntu

----------- On 32-bit Systems -----------------
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.deb
$ sudo dpkg -i mod-pagespeed-stable_current_i386.deb
$ sudo apt-get -f install

----------- On 64-bit Systems -----------------
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
$ sudo dpkg -i mod-pagespeed-stable_current_amd64.deb
$ sudo apt-get -f install

Installing mod_pagespeed from binary packages will add a Google’s official repository to your system, so that you can update the mod_pagespeed automatically using package manager called yum or apt.

What Mode_Pagespeed is Installed

Let’s see what packages mod_pagespeed installed on the system:

  1. It will install two modules, mod_pagespeed.so for Apache 2.2 and mod_pagespeed_ap24.so for Apache 2.4.
  2. It will install two main configuration files: pagespeed.conf and pagespeed_libraries.conf (for Debian pagespeed.load). If you change one of these configuration files, you will no longer receive future updates automatically.
  3. A standalone JavaScript minifier pagespeed_js_minify used to minify JS and create metadata for library canonicalization.

About Mod_Pagespeed Configuration and Directories

The module enables following configuration files and directories itself automatically during installation.

  1. /etc/cron.daily/mod-pagespeed : mod_pagespeed cron script for checking and installing latest updates.
  2. /etc/httpd/conf.d/pagespeed.conf : The main configuration file for Apache in RPM based distributions.
  3. /etc/apache2/mods-enabled/pagespeed.conf : The main configuration file for Apache2 in DEB based distributions.
  4. pagespeed_libraries.conf : The default set of libraries for Apache, loads at Apache startup.
  5. /usr/lib{lib64}/httpd/modules/mod_pagespeed.so : mod_pagespeed module for Apache.
  6. /var/cache/mod_pagespeed : File caching directory for web sites.

Important: In Nginx the configuration files of mod_pagespeed typically found under /usr/local/nginx/conf/ directory.

Configuring Mod_Pagespeed Module

In Apache, mod_pagespeed automatically Turn On when installed, while in Nginx you need to place following lines to your nginx.conf file and in every server block where PageSpeed is enabled:

pagespeed on;

- Needs to exist and be writable by nginx.  Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;

- Ensure requests for pagespeed optimized resources go to the pagespeed handler
- and no extraneous headers get set.
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
  add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }

Finally, don’t forget to restart your Apache or Nginx server to start mod_pagespeed working properly.

Step 4: Verifying Mod_Pagespeed Module

To verify mod_pagespeed module, we will use curl command to test in on domain or IP as shown:

- curl -D- http://192.168.0.15/ | less
Apache
HTTP/1.1 200 OK
Date: Fri, 04 Mar 2016 07:37:57 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
...
X-Mod-Pagespeed: 1.9.32.13-0
---
Nginx
HTTP/1.1 200 OK
Date: Fri, 04 Mar 2016 07:37:57 GMT
Server: nginx/1.4.0
...
X-Page-Speed: 1.5.27.1-2845
...

If you don’t see an X-Mod-Pagespeed header, that means mod_pagespeed isn’t actually installed.

Step 5: Turning the Module On and Off

If you don’t want to use mod_pagespeed completely, you can Turn Off by inserting the following line to pagespeed.conf file at the top.

ModPagespeed off

Similarly, to Turn On module, insert the following line to pagespeed.conf file at the top.

ModPagespeed on

As I said above after installing mod_pagespeed our website loads 40%-50% faster. We would really like to know about your website speed after installing it on your systems via comments.

For more details about configuration, you can check out the official mod_pagespeed page at https://developers.google.com/speed/pagespeed/module/.