How to enable/disable gzip compression in nginx on a Plesk server

Follow

Comments

20 comments

  • Avatar
    Markus

    Thanks a lot! Great 'n' easy tutorial.

    2
    Comment actions Permalink
  • Avatar
    adrian TNT

    Isn't text/html most important ? It is missing from the code.

    0
    Comment actions Permalink
  • Avatar
    Ekaterina Babenko

    @adrianTNT

    Hello Adrian! According to nginx official documentation, for the option gzip_types the mime-type text/html type is always compressed by default, so there is no need to specify it explicitly.
    You can check right here:
    https://nginx.org/en/docs/http/ngx_http_gzip_module.html

    2
    Comment actions Permalink
  • Avatar
    Lenusch

    Is there any disadvantages to enable gzip globally? We often have reqests if we can enable gzip - there i want to insert this globally. 

    But will this harm any Websites in whatever way? Or is failproved ?

    1
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    @Lenor,

    When compressing is enabled, additional server RAM & CPU resources are utilized to compress websites content on the fly. If there are many websites on the server, the load may increase dramatically.

    0
    Comment actions Permalink
  • Avatar
    Lenusch

    @Ivan uff. We have 300 Websites on a Server. Theres 64GB RAM. 

    Any example how i can determine if this will work or not? 

    0
    Comment actions Permalink
  • Avatar
    Robert Asilbekov

    @Lenor  If you mean how enabling gzip compression affect server performance - the only way is to monitor the server performance. Establish some performance baseline before enabling and see how the baseline will be changed after enabling gzip. 

     

    If you want to check whether gzip compression works you may use curl command. When gzip enabled you will see in the output 'Content-Encoding: gzip'. You can check individual files instead of pages to ensure they have been gzipped as well.

     #  curl -s -H "Accept-Encoding: gzip" -I http://domain.tld | grep Content-Encoding
    Content-Encoding: gzip

    0
    Comment actions Permalink
  • Avatar
    Berat Gashi

    Hi there,

    I need help on this one,

    I have a Plesk Server but the Additional nginx Directives is not showing at all even from the admin account!

     

    Plesk Info:

    OS ‪Ubuntu 18.04.2 LTS‬
    Product Plesk Onyx 
    Version 17.8.11 Update #39
    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello @Berat,

    Most probably this is because Nginx is not installed or disabled on your server.

    This article should help:
    https://support.plesk.com/hc/en-us/articles/213944825-How-to-install-and-enable-nginx-reverse-proxy-on-a-Plesk-for-Linux-server

    0
    Comment actions Permalink
  • Avatar
    Steve Yates

    I think the mime type for RSS should be application/rss+xml instead of application/xml+rss?

    0
    Comment actions Permalink
  • Avatar
    Alisa Kasyanova

    @Steve Yates
    Thank you for pointing it out! I have changed the article accordingly.

    0
    Comment actions Permalink
  • Avatar
    Markus (Edited )

    Hi Plesk Team,

    somewhere in Plesk Forums I got the information to set the serverwide nginx gzip configuration in the http section of /etc/nginx/nginx.conf. Is it correct or is it better like in your example for some reasons? I use ONLY NGINX (no Apache / no Proxy) for webhosting.

    http {

    ......

    gzip_static on;
    gzip on;
    gzip_proxied any;
    gzip_http_version 1.1;
    gzip_min_length 100;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml text/javascript image/x-icon image/bmp image/svg+xml application/javascript application/js application/xhtml+xml application/rss+xml application/x-font-ttf application/vnd.ms-fontobject font/opentype font/ttf font/eot font/otf image/jpg image/jpeg image/png image/gif application/json;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    ......

    }

    0
    Comment actions Permalink
  • Avatar
    Konstantin Annikov (Edited )

    Hello, 

    Yes, you can define all the settings in main configuration file and they will work for all hosted websites. There are no known reasons to not to do it.
    However defining additional directives in separate file (in article it is /etc/nginx/conf.d/gzip.conf) is like a best practice for nginx.

    1
    Comment actions Permalink
  • Avatar
    Nerque

    When you enable the gzip option in nginx, do you need to enable it in apache as well, or do you have to choose between the two? I'm saying this because I think it's usual to have nginx as an apache proxy.

    0
    Comment actions Permalink
  • Avatar
    Maxim Krasikov

    Hi @Nerque,

    Since Nginx is used as an Apache proxy, gzip compression should be enabled for Nginx and disabled for Apache. In this configuration, static files are served by Nginx.

    Information on how to enable compression for Apache can be found here:
    https://support.plesk.com/hc/en-us/articles/115000716649

     
    0
    Comment actions Permalink
  • Avatar
    Mannan Raimagia

    Hello I can't find the option you are talking about in Enabling gzip compression for a domain in Plesk 

    There is no such option available of the name Additional nginx directives where I can put the code

    0
    Comment actions Permalink
  • Avatar
    Yulia Plokhotnikova

    Hello @Mannan Raimagia,

    The menu is not available for non-admin users. You logged in as a customer, so you cannot manage additional nginx directives. I will add the explanation in the article to make it complete. 

    Now, for you to add the additonal nginx directives, contact your Plesk provider who sent you access details to Plesk. Your provider, as Plesk administrator, can manage additional nginx directives.

    0
    Comment actions Permalink
  • Avatar
    Motaz Elshazly (Edited )

    When using that configuration in Plesk, I get the following error (Screenshot attached):

    "Invalid INI syntax detected on line 2: 'gzip_disable `MSIE [1-6].(?!.*SV1)`;'"

    I thought it was related to the double quote, tried single and ` but got the same error. Could you please assist? thank you.

    1
    Comment actions Permalink
  • Avatar
    Kuzma Ivanov

    Hi Motaz Elshazly

    It looks like you trying to add additional nginx directives to the field in PHP Settings instead of nginx settings.

    The correct field is at Domains > example.com > Hosting & DNS > Apache & nginx Settings > Additional nginx directives.

    0
    Comment actions Permalink
  • Avatar
    Robert Alexander

    Worked a treat for me. Thanks.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request