facelordgists
5/11/2013 - 5:02 AM

SERVER: nginx & apache - Enable Gzip & future headers + disable etags

SERVER: nginx & apache - Enable Gzip & future headers + disable etags

#enable nginx server-wide Gzipping

First, open /etc/nginx/nginx.conf Then add the following lines inside the http{}

gzip on;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_static on;
gzip_vary  on;
gzip_proxied any;
gzip_min_length 1400;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

#Add Expires headers to nginx virtual domain config

mkdir /usr/local/psa/admin/conf/templates/custom/domain

cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/

add or change what you need in

/usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php

This should be a clone of the standard config, except you need to find the part in the first tag that applies to the site, rather than the webmail domain.

Find the location tag that contains the root / of the site and add this

if ($request_uri ~* ".(png|ico)\?[0-9]+$") {
    expires 30d;
    access_log off;
    add_header Cache-Control "public";
    break;
}

Find the location tag thaxt is for internal-nginx-static-location and inside it add this code. Reference this file from Plesk 11

expires 1M;
access_log off;
add_header Cache-Control "public";

#Disable Apache etag headers

Edit Apache's vhost config to disable etag headers here

/usr/local/psa/admin/conf/templates/default/domain/domainVirtualHost.php

Once in there add this code right above <IfModule mod_userdir.c>

<ifModule mod_expires.c>
    ExpiresActive On

    # special MIME type for icons - see http://www.iana.org/assignments/media-types/image/vnd.microsoft.icon
    AddType image/vnd.microsoft.icon .ico
    # now we have icon MIME type, we can use it
    # my favicon doesn't change much
    ExpiresByType image/vnd.microsoft.icon "access plus 1 years"

    ExpiresByType image/gif "access plus 1 months"
    ExpiresByType image/jpg "access plus 1 months"
    ExpiresByType image/jpeg "access plus 1 months"
    ExpiresByType image/png "access plus 1 months"
    ExpiresByType image/vnd.microsoft.icon "access plus 1 months"
    ExpiresByType image/x-icon "access plus 1 years"
    ExpiresByType image/ico "access plus 1 years"
    ExpiresByType application/javascript "now plus 1 months”
    ExpiresByType application/x-javascript "now plus 1 months”
    ExpiresByType text/javascript "now plus 1 months”
    ExpiresByType text/css "now plus 1 months”
    ExpiresDefault "access plus 1 days"

    Header unset ETag
    FileETag None
</ifModule>

Then have plesk regenerate every site's configuration files

/usr/local/psa/admin/bin/httpdmng --reconfigure-all

restart apache

/etc/init.d/httpd restart graceful

restart nginx

service nginx restart