Enable Gzip Compression in Nginx?

Aaron Lavers

Member
Registered
Joined
May 20, 2016
Messages
61
Points
8
I am find easy ways to enable Gzip compression in nginx? could anyone please tell me to do this?
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
Here the correct config for gzip :


Code:
[COLOR=#666666][FONT=Consolas]gzip on;
[/FONT][/COLOR]gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6].(?!.*SV1)";
[COLOR=#666666][FONT=Consolas]gzip_vary on;[/FONT][/COLOR]
 

Aaron Lavers

Member
Registered
Joined
May 20, 2016
Messages
61
Points
8
Aaron Lavers
Where to add these codes? nginx.conf file in /etc/nginx/?
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
VirtuBox
Exactly, your nginx.conf file should look like :

Code:
user www-data;worker_processes auto;
worker_rlimit_nofile 100000;
pid /run/nginx.pid;


events {
        worker_connections 4096;
        multi_accept on;
}


http {


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


        server_tokens off;
        reset_timedout_connection on;
        add_header rt-Fastcgi-Cache $upstream_cache_status;


        # Limit Request
        limit_req_status 403;
        limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;


        # Proxy Settings
        # set_real_ip_from      proxy-server-ip;
        # real_ip_header        X-Forwarded-For;


        fastcgi_read_timeout 300;
        client_max_body_size 100m;


        ##
        # SSL Settings
        ##


        ssl_session_cache shared:SSL:20m;
        ssl_session_timeout 10m;
        ssl_prefer_server_ciphers on;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-A$
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;


        ##
        # Basic Settings
        ##
        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;


         ##
        # Logging Settings
        ##


        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;


        # Log format Settings
        log_format rt_cache '$remote_addr $upstream_response_time $upstream_cache_status [$time_local] '
        '$http_host "$request" $status $body_bytes_sent '
        '"$http_referer" "$http_user_agent"';


        ##
        # Gzip Settings
        ##


        gzip on;
        gzip_disable "msie6";


        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_types
            application/atom+xml
            application/javascript
            application/json
            application/rss+xml
            application/vnd.ms-fontobject
            application/x-font-ttf
            application/x-web-app-manifest+json
            application/xhtml+xml
            application/xml
            font/opentype
            image/svg+xml
            image/x-icon
            text/css
            text/plain
            text/x-component
            text/xml
            text/javascript;


        ##
        # Virtual Host Configs
        ##


        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}
 

Luxin Host

Well-known member
Registered
Joined
Jun 26, 2016
Messages
543
Points
43
I am find easy ways to enable Gzip compression in nginx? could anyone please tell me to do this?
Star with connecting to your hosting via SSH.

Then you will need to configure the configuration file, do that by editing it:
sudo nano /etc/nginx/nginx.conf

Now un-comment the things you want and comment the things you dont want. (or use a ready configureation form sofwhere else such as here)

After configuring the configuration file to your needs, save/close it and restart nginx.
nginx restart

NOTE:
modify the command to suit your OS
Use config settings best to your needs
where I used nano to edit you can use anything else.

If you need specific help with your OS or any specific help let me know as this tutorial was pretty general.
 
Newer Threads
Recommended Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top