Enable GZIP Compression Apache Nginx and Leverage Browser Caching on CentOS, CloudLinux, RedHat, Plesk Onyx

KVM VPS Hosting AdvertisementKVM VPS Unlimited Bandwidth

KVM VPS Hosting with KVM VPS Unlimited Bandwidth, KVM virtual private server hosting starting at only $30 a month. Cheap KVM Hosting up to 6 Cores @ 2.83Ghz, 12GB Memory, 1TB RAID-10 with Unlimited Bandwidth.

 

Enable GZIP Compression Apache Nginx and Leverage Browser Caching on CentOS, CloudLinux & RedHat, Plesk Onyx

If you own a dedicated server or have a virtual private server you can enable GZIP compression apache nginx on CentOS, Plesk, CloudLinux & RedHat based operating systems and also enable Leverage Browser Caching on CentOS, CloudLinux and Redhat systems.

You can follow this tutorial for other systems as well if you know where the apache and nginx or just apache configurations are located. You can always use the command find / -name httpd.conf for an example.

Enabling GZIP Compression Apache Nginx and Leverage Browser Caching on CentOS will decrease the load time of all your customers websites, as setting this will be server wide. Having faster loading websites is essential to having a higher ranking in search engines and better visitor traffic for your website and your web hosting customers.

Plesk httpd.conf

If you have Parallels Plesk Panel now known as Odin Plesk Onyx or cPanel it does not compress all filetypes by default or enable leverage browser caching on your system. This tutorial was written using CloudLinux 7 and Odin Plesk Onyx server, but the first part was written when I had CloudLinux 6 and Plesk Panel 12 or so, I recommend creating the GZIP portion of this tutorial in a new file or already existing file inside the directory /etc/httpd/conf.d/ or just follow how it is now, which works perfectly fine.

cPanel httpd.conf

If

 

find / -name httpd.conf
/etc/apache2/conf/httpd.conf
/usr/local/apache/conf/httpd.conf

 

ps. If you don’t have nano, just run command yum install nano or be one of those cool vi people 🙁

 

Enable GZIP Compression Nginx Plesk, CentOS, CloudLinux or RedHat

nano /etc/nginx/nginx.conf

 

Enable GZIP Compression Apache Nginx on Plesk

Enable GZIP Compression Apache Nginx on CentOS, Plesk CloudLinux and how to enable GZIP Compression Apache CentOS on Plesk Panel 12- Lee CLaxton Sarasota

 

 

 

 

Add before  }

gzip on;
gzip_comp_level 9;
gzip_http_version 1.1;
gzip_proxied any;
gzip_min_length 10;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/xhtml+xml;

New GZIP Types

gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/xhtml+xml application/javascript application/json application/vnd.ms-fontobject application/x-font-truetype font/eot font/opentype font/otf image/svg+xml image/vnd.microsoft.icon;

 

# Disable for IE < 6 because there are some known problems
gzip_disable “MSIE [1-6].(?!.*SV1)”;

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

 

Enable GZIP Compression Nginx

Enable GZIP Compression Nginx on Plesk, CentOS, CloudLinux & RedHat based systems. Enable GZIP Compression Nginx and Enabling GZIP Compression Apache is important to any web hosting provider

 

Run The Below Command and Fix Any Nginx Errors in Configuration

nginx -t

Restart Nginx
service nginx restart

Enable GZIP Compression Apache Plesk, CentOS, CloudLinux or RedHat

 

Must have mod_deflate enabled on your server. When you run this command and a # in front, you will need to edit and uncomment mod_deflate.

Check Mod_Deflate on CentOS 6

grep “mod_deflate” /etc/httpd/conf/httpd.conf

Check Mod_Deflate on CentOS 7

grep “mod_deflate” /etc/httpd/conf.modules.d/*.conf

Enable Mod_Deflate on CentOS 6

If # exists in front of the output uncomment it.

nano /etc/httpd/conf/httpd.conf

uncomment out LoadModule mod_deflate/LoadModule mod_deflate

Enable Mod_Deflate on CentOS 7

If # exists in front of the output uncomment it.

nano /etc/httpd/conf.modules.d/00-base.conf

uncomment out LoadModule deflate_module modules/mod_deflate.so

Backup your apache configuration file.
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup

Now edit your apache configuration and add the extensions you want to compress.

nano /etc/httpd/conf/httpd.conf

 

Enable GZIP Compression Apache CentOS

Enable GZIP Compression Apache Plesk, CentOS, CloudLinux or RedHat systems. Enable GZIP Compression CentOS 6.7 running Plesk Panel 12

 

 

 

Add to end of file.

Add it below:

AddOutputFilter INCLUDES .shtml
AddType text/html .shtml
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .p

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

 

While adding this to your files, restart the service after any changes to make sure no conflicts appear, and fix as necessary, you can also use httpd -t and nginx -t commands to see if any problems in nginx and httpd configuration.\

Check Nginx and Apache Configuration for Errors

nginx -t

httpd -t

Restart Nginx
service nginx restart

Restart Apache 

service httpd restart

Use a HTTP Compression Tester, such as WhatsMyIp.org HTTP Compression Checker to verify HTTP Compression. If all goes successful, you will have enable gzip compression apache nginx on CentOS, CloudLinux, Plesk and Redhat based operating systems. Essential to any web hosting company.

 

Leverage Browser Caching on CentOS, RedHat, CloudLinux and Plesk Onyx

Create a file inside /etc/httpd/conf.d/ I had problems with adding it inside /etc/httpd/conf.modules.d/ so just use /etc/httpd/conf.d/

nano /etc/httpd/conf.d/expires.conf

ps. If you don’t have nano, just yum install nano or be one of those cool vi people 🙁

WARNING, If yours does not show leverage browser caching on CentOS working after restarting apache and running the tests, you should try to add the below. Such add <IfModule mod_expires.c> right below LoadModule expires_module modules/mod_expires.so I’ll leave it commented out for you guys can just copy and paste it in and uncomment <IfModule mod_expires.c> and </IfModule> if your tests show leverage browser caching is not working.

Paste every thing below into a new file /etc/httpd/conf.d/expires.conf to enable Leverage Browser Caching in Plesk Onyx and should work for Plesk 12.5 as well.

Note: The below LoadModule path should work, if it does not run the below command to find it.

find / -name mod_expires.so

nano /etc/httpd/conf.d/expires.conf

LoadModule expires_module modules/mod_expires.so

######### Custom Added to Enable Leverage Browser Caching on CentOS ########
#<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault “access plus 14 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/pdf “access plus 1 month”
ExpiresByType text/javascript “access plus 1 month”
ExpiresByType text/x-javascript “access plus 1 month”
ExpiresByType application/javascript “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 1 days”
#</IfModule>
##########################################################

After you have done that edit /etc/httpd/conf/httpd.conf and add FileETag None

nano /etc/httpd/conf/httpd.conf

FileETag None

Before you restart Apache run the below command to make sure no errors inside apache configuration files.

httpd -t

Now that you’re done with Browser Caching, GZIP for CentOS 6/7 running Plesk, follow directions and you can also adapt the information to cPanel and other servers.

services httpd restart

or

systemctl restart httpd.service

While you’re at it go ahead and restart nginx.

service nginx restart

or

systemctl restart nginx.service

 

Test Browser Caching and GZIP Compression using Pingdom Tools.

https://tools.pingdom.com/

Test GZIP Compression using checkzipcompression.com

https://checkgzipcompression.com/

You can view all the apache modules your server is loading by typing the below command.

httpd -M

If you want to check for expires and header in apache do the commands below.

httpd -M | grep expires

httpd -M | grep header

 

This tutorial is proudly written by Alpha Computer and Web Services to help people get there own servers up and running for top performance. Lots of other apache and nginx optimizations to do, but you’re one step slower to optimizing apache and nginx.

 Computer Repair in Sarasota

By Lee Claxton Sarasota

Sarasota FL Computer Repair

5439 Sawgrass RD, Sarasota FL 34232

941-539-9680

Shared Web Hosting |   Linux Server Services