Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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


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";

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


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

<ifModule mod_expires.c>
    ExpiresActive On

    # special MIME type for icons - see
    AddType image/ .ico
    # now we have icon MIME type, we can use it
    # my favicon doesn't change much
    ExpiresByType image/ "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/ "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

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

This comment has been minimized.

Copy link

nicocolt commented Mar 16, 2016


This conf sets in Plesk 12.0.8 doesn't work with hosted Prestashop 1.6.x. Customers are unable to login/logout.

Best regards,


This comment has been minimized.

Copy link

nicocolt commented Mar 16, 2016


Setting ExpiresDefault "access plus 0 minutes" instead of ExpiresDefault "access plus 1 days" solved the issue. The fact is that the ExpiresDefault directive includes the html files. You can also specify explicitly the Expires directive for the html files like this: ExpiresByType text/html "access plus 0 minutes" (not tested on my side)

Best regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.