Print
Parent Category: Tutorials
Hits: 1723

Today we will talk about Linux and Nginx  tips and tricks that will help webmaster to tune their dedicated server to handle high traffic.

Nginx configuration nginx.conf is a file file, usually located at /etc/nginx/nginx.conf path containing configuration settings for nginx server. Cannot find the location of the file? Use locate command: >cd / then >locate nginx.conf. You may find the values in conf/extra directory. 

Main parameters to tune are:

worker_processes. I usualy set to 4. Default is 1, so:

worker_processes  4;

keepalive_timeout, default is set to 0 i'm using 65:

keepalive_timeout  65;

client_max_body_size 1000M;

Another crucial parameter for increasing nginx speed is Nginx Compression. So let's see how we can serve compressed content from ngix and increase response time:

#Compression

    gzip  on;

    gzip_static on;

    gzip_comp_level 2;

    gzip_min_length 1000;

    gzip_buffers 32 8k;

    gzip_proxied    expired no-cache no-store private auth;

    gzip_types      text/plain text/css text/javascript text/xml application/x-javascript application/xml application/xml+rss;

    # Disable for IE < 6 because there are some known problems

    gzip_disable "MSIE [1-6].(?!.*SV1)";

    # Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6

    gzip_vary on;

    set $cache_uri $request_uri;

    # POST requests and urls with a query string should always go to PHP

        if ($request_method = POST) {

                set $cache_uri 'null cache';

        }

        if ($query_string != "") {

                set $cache_uri 'null cache';

        }

    # Don't cache uris containing the following segments

    if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {

                set $cache_uri 'null cache';

    }

    # Don't use the cache for logged in users or recent commenters

    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {

                set $cache_uri 'null cache';

    }

    # Cache static files for as long as possible

    location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {

                expires max; log_not_found off; access_log off;

    }

Note:

We use Hosting and VPS Hosting, from: www.star-host.org

We like and trust them.

Good prices, high security.