GZIP compression

Discussion in 'Installation/Configuration' started by AxelssonDesign, Jul 3, 2017.

  1. Hello,
    When I add gzip compression code to options>nginx directives It will not work.

    Code:
    # Enable Gzip compression
    gzip          on;
    # Compression level (1-9)
    gzip_comp_level     5;
    # Don't compress anything under 256 bytes
    gzip_min_length     256;
    # Compress output of these MIME-types
    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/rss+xml
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-javascript
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/svg+xml
        image/x-icon
        text/css
        text/plain
        text/javascript
        text/x-component;
    # Disable gzip for bad browsers
    gzip_disable  "MSIE [1-6]\.(?!.*SV1)";
    How can I fix this ?
     
  2. ahrasis

    ahrasis Active Member

    I enabled all under gzip in nginx.conf for mine and it works on all sites. I am not sure whether this can be enabled individually like what you are trying to do though.
     
  3. Thanks for answer ahrasis.
    I'm wondering if this can be done on individual site basis.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Take a look at the nginx documentation to see if the gzip options are allowed inside a server { } block. If yes, then you can set them in the nginx directives field of the website.
     
  5. ahrasis

    ahrasis Active Member

    Based on this it should work on individual site basis. And based on nginx doc, you can put it either under server or location {..}. Thus, I suspect your code is missing something in it.
     
  6. Now the first code is working from Option>nginx Directives:, but this code is giving media 8 days and other three 9 years.

    Code:
    location ~* \.(txt|xml|js)$ {
        expires 8d;
    }
    location ~* \.(css)$ {
        expires 8d;
    }
    location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$ {
        expires 8d;
    }
    location ~* \.(jpg|jpeg|png|gif|swf|webp)$ {
        expires 8d;
    }
    Is there an error in the code ?
     
  7. ahrasis

    ahrasis Active Member

    I don't see any. May be you need to give it some times.

    I also noted those are mostly needed nowadays, so I personally customized nginx_vhost.conf.master in my conf-custom directory to include them in all websites rather than inserting them in each and every website directive via ISPC.
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Ensure that the vhost file of this site has not been saved with a .err file ending. in the nginx sites-available folder. If that's the case, then there is probably a typo somewhere in the custom config code so that nginx rejected it.
     
  9. Thanks for replay @till.

    This site has no .err file. Here is the eistnaflug.is.vhost code:

    Code:
    server {
            listen 45.76.92.39:80;
            listen [2001:19f0:6c01:413:5400:ff:fe6a:a0e5]:80;
    
            listen 45.76.92.39:443 ssl;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            listen [2001:19f0:6c01:413:5400:ff:fe6a:a0e5]:443 ssl;
            ssl_certificate /var/www/clients/client3/web23/ssl/eistnaflug.is-le.crt;
            ssl_certificate_key /var/www/clients/client3/web23/ssl/eistnaflug.is-le.key;
    
            server_name eistnaflug.is www.eistnaflug.is;
    
            root   /var/www/eistnaflug.is/web/;
    
            if ($http_host = "www.eistnaflug.is") {
                rewrite ^ $scheme://eistnaflug.is$request_uri? permanent;
            }
            if ($scheme != "https") {
                rewrite ^ https://$http_host$request_uri? permanent;
            }
    
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
            location ~ \.shtml$ {
                ssi on;
            }
    
    
            error_page 400 /error/400.html;
            error_page 401 /error/401.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 405 /error/405.html;
            error_page 500 /error/500.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
            recursive_error_pages on;
            location = /error/400.html {
    
                internal;
            }
            location = /error/401.html {
    
                internal;
            }
            location = /error/403.html {
    
                internal;
            }
            location = /error/404.html {
    
                internal;
            }
            location = /error/405.html {
    
                internal;
            }
            location = /error/500.html {
    
                internal;
            }
            location = /error/502.html {
    
                internal;
            }
            location = /error/503.html {
    
                internal;
            }
    
            error_log /var/log/ispconfig/httpd/eistnaflug.is/error.log;
            access_log /var/log/ispconfig/httpd/eistnaflug.is/access.log combined;
    
            location ~ /\. {
                deny all;
            }
    
            location ^~ /.well-known/acme-challenge/ {
                access_log off;
                log_not_found off;
                root /usr/local/ispconfig/interface/acme/;
                autoindex off;
                index index.html;
                try_files $uri $uri/ =404;
            }
    
            location = /favicon.ico {
                log_not_found off;
                access_log off;
            }
    
            location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            location /stats/ {
    
                index index.html index.php;
                auth_basic "Members Only";
                auth_basic_user_file /var/www/clients/client3/web23/web/stats/.htpasswd_stats;
            }
    
            location ^~ /awstats-icon {
                alias /usr/share/awstats/icon;
            }
    
            location ~ \.php$ {
                try_files /d9c0b5be512af618ae73d319a628a04e.htm @php;
            }
    
            location @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/lib/php5-fpm/web23.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
            location /cgi-bin/ {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                root /var/www/clients/client3/web23;
                gzip off;
                fastcgi_pass  unix:/var/run/fcgiwrap.socket;
                fastcgi_index index.cgi;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
    
    
            location / {
            try_files $uri $uri/ /index.php?$args;
            }
            rewrite /wp-admin$ $scheme://$host$uri/ permanent;
            location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
            expires max;
            log_not_found off;
            }
    
            location ~ \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
                add_header Access-Control-Allow-Origin *;
                expires 1M;
                access_log off;
                add_header Cache-Control "public";
            }
    
            rewrite ^/(.*/)?sitemap.xml /wp-content/uploads/sitemap.xml last;
    
            gzip          on;
            gzip_comp_level     5;
            gzip_min_length     256;
            gzip_types
                application/atom+xml
                application/javascript
                application/json
                application/rss+xml
                application/vnd.ms-fontobject
                application/x-font-ttf
                application/x-javascript
                application/x-web-app-manifest+json
                application/xhtml+xml
                application/xml
                font/opentype
                image/svg+xml
                image/x-icon
                text/css
                text/plain
                text/javascript
                text/x-component;
            gzip_disable  "MSIE [1-6]\.(?!.*SV1)";
    
    
            location ~* \.(txt|xml|js)$ {
                expires 8d;
            }
            location ~* \.(css)$ {
                expires 8d;
            }
            location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$ {
                expires 8d;
            }
            location ~* \.(jpg|jpeg|png|gif|swf|webp)$ {
                expires 8d;
            }
    
    
    
    
    }
    Site zix.is has .err file but works correctly.
     

Share This Page