Server Setup

Apache Performance Ultimate Configuration

by , , revisited on


We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install NGINX, Varnish and lots of useful modules for them, this is your one stop repository to get all performance related software.
You have to maintain an active subscription in order to be able to use the repository!

We open our work for free. Here is drop-in Apache performance configuration file to enable maximum performance as per modern performance guidelines. Here is what it does:

  • Disables Etag header
  • Enables GZIP compression for static files: Javascript, CSS, etc.
  • Enables Far Future Expires headers for static files: Javascript, CSS, images
  • Properly sets MIME type for some file types
  • Makes it harder for hackers to understand the type of sites by spoofing Powered-By header

Most of performance tips by Google PageSpeed Insights will be addressed by this configuration.

Simply save it to /etc/httpd/conf.d/z_performance.conf. The filename starts with “z” to make sure it is loaded last in queue of configuration files.

Ultimate Apache Performance file: z_performance.conf

AddType text/javascript .js
AddType application/java-archive .jar
# Correct MIME type to use (as per Wikipedia). Also this ensures that IE8 can read the icon
AddType image/x-icon .ico
AddType image/x-icon .cur
# Add correct content-type for fonts
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType image/svg+xml .svg

# enable KeepAlive for persistent connections to work
# KeepAlive On

FileETag none

# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems (so does IE 6)
BrowserMatch ^Mozilla/4\.[0678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE\s7  !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|gz|jar|rar|zip|7z)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

# enable expirations
ExpiresActive On
ExpiresByType text/javascript "access plus 2 years"
ExpiresByType text/css "access plus 2 years"
ExpiresByType image/gif "access plus 2 years"
ExpiresByType image/jpeg "access plus 2 years"
ExpiresByType image/png "access plus 2 years"
ExpiresByType image/x-icon "access plus 2 months"

# Add a far future Expires header for fonts
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"

Header unset X-Powered-By
Header set X-Powered-By "ASP.NET"

# protect .svn directories
RedirectMatch 404 /\\.svn(/|$)

AddDefaultCharset Off

After you’re done saving the file, simply reload Apache service to apply optimizations:

service httpd reload
Apache Performance Injection
Apache Performance Injection Complete

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.