3

gzip shows as not enabled on my vps site and not even the tech support of my host, asmallorange, can figure out the cause of my problem. I've documented my exact set-up (nothing more than this was done):

  1. I installed centos 7 minimal
  2. I logged in via putty
  3. Then i input the following commands

    1. yum update
    2. yum clean all
    3. yum install epel-release
    4. yum install nginx
    5. systemctl enable nginx
    6. vi /etc/nginx/nginx.conf

      user nginx;
      worker_processes auto;
      error_log /var/log/nginx/error.log;
      pid /run/nginx.pid;
      
      events {
          worker_connections 1024;
      }
      
      http {
          log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';
      
          access_log  /var/log/nginx/access.log  main;
      
          sendfile            on;
          tcp_nopush          on;
          tcp_nodelay         on;
          keepalive_timeout   65;
          types_hash_max_size 2048;
      
          server_tokens       off;
      
          include             /etc/nginx/mime.types;
          default_type        application/octet-stream;
      
          limit_conn_zone     $binary_remote_addr zone=addr:8m;
          limit_req_zone      $binary_remote_addr zone=mylimit:16m rate=16r/s;
      
          server {
              listen       80 default_server;
              listen       [::]:80 default_server;
              server_name  abcj.me;
              root         /srv;
              index        index-l1.html
      
              gzip            on;
              gzip_vary       on;
              gzip_min_length 1024;
              gzip_types      text/css text/plain;
      
              client_body_timeout 8;
              client_header_timeout 8;
      
              location ~*  \.(css|ico|jpeg|jpg|js|mp3|mp4|pdf|png|txt|webp|zip)$ {
                  expires 16d;
              }
      
              location ~*  \.(html)$ {
                  expires 1d;
              }
      
              error_page 404 /404-l1.html;
                  location = /40x.html {
              }
      
              error_page 500 502 503 504 /50x.html;
                  location = /50x.html {
              }
          }
      
          server {
              listen 80;
              server_name www.abcj.me;
              return 301 http://abcj.me$request_uri;
          }
      }
      
    7. service nginx restart

  4. I uploaded index-l1.html to srv via winscp

nginx -V 2>&1 | tr -- - '\n' | grep module shows that i have

  • http_gzip_static_module
  • http_gunzip_module

curl -H "Accept-Encoding: gzip" -I http://example.me/index-l1.html does not show gzip acceptance.

https://www.example.com/gzip-test/ does not show gzip acceptance

0

1 Answer 1

2

· the gzip commands need to be directly in the http block, not in the server block

user nginx; 
worker_processes auto; 
error_log /var/log/nginx/error.log; 
pid /run/nginx.pid; 

events { 
worker_connections 1024; 
} 

http { 
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
'$status $body_bytes_sent "$http_referer" ' 
'"$http_user_agent" "$http_x_forwarded_for"'; 

access_log /var/log/nginx/access.log main; 

sendfile on; 
tcp_nopush on; 
tcp_nodelay on; 
keepalive_timeout 65; 
types_hash_max_size 2048; 

server_tokens off; 

include /etc/nginx/mime.types; 
default_type application/octet-stream; 

limit_conn_zone $binary_remote_addr zone=addr:8m; 
limit_req_zone $binary_remote_addr zone=mylimit:16m rate=16r/s; 

gzip on; 
gzip_vary on; 
gzip_min_length 1024; 
gzip_types text/css text/plain; 

server { 
listen 80 default_server; 
listen [::]:80 default_server; 
server_name abcj.me; 
root /srv; 
index index-l1.html 

client_body_timeout 8; 
client_header_timeout 8; 

location ~* \.(css|ico|jpeg|jpg|js|mp3|mp4|pdf|png|txt|webp|zip)$ { 
expires 16d; 
} 

location ~* \.(html)$ { 
expires 1d; 
} 

error_page 404 /404-l1.html; 
location = /40x.html { 
} 

error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
} 
} 

server { 
listen 80; 
server_name www.abcj.me; 
return 301 http://abcj.me$request_uri; 
} 
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.