• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved CentOS 6: adding GZIP compression to nginx

SacAutos

Regular Pleskian
I have a domain that just servers javascript (.js) files as part of my overall CDN scheme. I realized the other day that I could improve my website performance if I enabled GZIP for nginx. I found several useful posts on the internet that stated, in summary, if I added these directives:

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary on;

into a file called /etc/nginx/conf.d/gzip.conf on my server and restarted nginx, that gzip would be enabled. Well, it didn't work. I went back through the panel and checked the Apache/nginx settings. All the boxes for smart serving of content were all on.

Thinking that perhaps I could enable gzip for just the domain, I added the directives above to my vhost_nginx.conf file (I had previously created one) and restarted nginx. Still no gzip compression.

Anybody have any ideas why this wouldn't be working? Additional things to check or test would help. Thanks!
 
The Knowledgebase article is one of the ones that I referenced. And the Check GZIP compression website was the one that I used to check whether it was working. So we're in sync on that. Unfortunately, I still don't have compression working. :(
 
In Plesk, go into your NGINX settings and add this to the addtitional settings at the bottom of the screen. When you save the config, it will restart NGINX and you'll be set. If you only want to GZIP Javascript, you can remove the other items from the list.

gzip on;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
image/svg+xml;
gzip_vary on;
gzip_disable “msie6”;
 
Thank you for your suggestion. I'm running Plesk Onyx 17.5.3. I don't see any place where I can enter additional nginx settings. What's the menu path?
 
Websites & Domains > <domain_name> > Apache & nginx Settings.

Scroll down to the bottom of the page. To add custom nginx directives for a website, use the Additional nginx directives field.

Copy and paste my NGINX gzip above and SAVE. You're done.
 
When I log in as admin, I click on the subscriptions menu on the left. I select the subscription that I want to update. Then I click on the Apache / nginx settings that you see.
 
I select the subscription that I want to update.
Do you click on subscription name or on "Manage in Customer Panel" link? In the first case, you will manage subscription as admin and in the second case - as subscription owner.
Look, here I'm logged to subscription as admin and I see additional nginx directives:

Screenshot at Jun 21 11-12-02.png

Compare it with your screenshot.
 
I've always been clicking on the far-right link to "Manage in Customer Panel." When I click on the actual Subscription link on the left side, I get more options!

Here is what I found already stored in the nginx settings. The options are exactly as I have set them in my vhost_nginx.conf file:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 7d;
add_header Pragma public;
add_header Cache-Control "public";
try_files $uri @fallback;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary on;
}
 
The previous entry might be in error, so I adjusted it to look like this instead:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 7d;
add_header Pragma public;
add_header Cache-Control "public";
try_files $uri @fallback;
}
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary on;

Still no compression. :(
 
This code works fine for me

gzip on;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_comp_level 9;
gzip_types text/plain text/xml text/css application/javascript text/javascript application/x-javascript image/gif image/png;
 
I'm delighted that, with help from the members of this forum, we were able to get this working. I have to wonder aloud, though, why the inclusion of the gzip.conf file for nginx system-wide didn't work. Was it the wrong options? Should the Knowledge Base article be updated? I'm grateful that I got it working. It just seemed harder than it should have been.
 
Back
Top