Nginx: High Performance

From OnnoWiki
Jump to navigation Jump to search

Sumber: https://www.monitis.com/blog/6-best-practices-for-optimizing-your-nginx-performance/



According to Wiki, “Nginx (pronounced “engine-x”) is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server).” While everyone has heard of Apache, Nginx is also up there in popularity and together both are responsible for serving over 50% of the traffic on the internet. In terms of the top-ranked websites in the world, Nginx actually comes out ahead of Apache, powering 45% of those sites ranked in the top 10,000 by traffic volume. The reason for the fast adoption of Nginx is because of its speed; it was created to deal with the C10K problem, which was a challenge of the modern web as more and more servers had to begin handling ten thousand concurrent connections.



optimizing nginx performance



The usage numbers indicate the reliance that folks place on Nginx to run their web services, especially those with the highest amount of traffic. It’s a proven, reliable tool. But as with any application you should always make sure things are running as smoothly and securely as possible. Here are 6 best practices that will guarantee you’re getting the most out of your Nginx setup.


1. Adjust worker_processes


The Nginx master and worker process architecture is explained as follows: “nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests. nginx employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes.”


In other words, worker_processes tells your virtual server how many cores are assigned to each processor so that Nginx can manage the concurrent requests in an optimized way. The default Nginx configuration path is: /etc/nginx/nginx.conf


To find out how many processors you have in your web server, run the following command.


grep processor /proc/cpuinfo | wc –l


In this case, the output number shows 1 core CPU.


It is common practice to run 1 worker process per core, so in this case you should set work processes to 1 for the greatest performance in the Nginx configuration file.


worker_processes 1;


2. Maximize worker_connections


Worker connections tells worker processes how many clients can be served simultaneously by Nginx. The default value for this is 768 but it’s important to keep in mind that each browser will usually open at least 2 server connections. The maximum number for the worker connections setting is 1024 and it’s best to use this to get the full potential from Nginx. On this basis then, assuming 1 core for each worker process, setting worker_connections to 1024 implies that Nginx can serve 1024 clients/second.


3. Enable Gzip Compression


Gzip is a software application used for file compression and decompression. Most servers and clients today support gzip. When a gzip compatible browser requests a resource the server will compress the response before sending it to the browser. Gzip is a great way to optimize your Nginx server as well to make things even more efficient. There are a few simple steps to turn on Gzip within your Nginx environment. According to one source: Create a file at /etc/nginx/conf.d/gzip.conf with the following content:


gzip on;

gzip_proxied any;

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

gzip_vary on;

gzip_disable “MSIE [1-6]\.(?!.*SV1)”;


Once that file is in place you simply restart your server and you’ll now be serving site assets with gzip compression.


site with gzip compression


4. Enable Cache for Static Files


Caching is a mechanism for the temporary storage of web pages in order to reduce bandwidth and improve performance. When a visitor arrives at your site the cached version will be served up unless it has changed since the last cache. Within your Nginx environment, you can add the following commands to tell your computer to cache the web page’s static files for faster accessibility. The default location for this is:


etc/nginx/sites-available/sitename

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {

  expires 365d;

}


In this example, all .jpg, .jpeg, .png, .gif, .ico, .css, and .js files get an Expires header with a date 365 days in the future from the browser access time.


5. Disable access_logs


Nginx logs each and every action in a log file named “access.log.” If you don’t require this information then it’s preferable to disable it, which will save your environment a bunch of additional processing and hard drive space too. To turn off the logs, simply write condition off next to the access_log syntax as in the following:


access_log off;


6. Monitor Your Nginx Servers with Monitis


If you’re looking for best-in-class website and server monitoring and performance tracking then you need to head over to Monitis. With its industry-leading global service, Monitis lets businesses monitor the heart of their infrastructure anytime and from anywhere. If you want less worry and hassle, then why not monitor your Nginx servers with Monitis? Imagine being able to get first-hand optics on your server health and performance in a cloud-based environment, so you learn about potential problems before your customers find out. By keeping your server infrastructure running smoothly and more effectively, Monitis alleviates the stress and helps you focus on running your business.




If you’re serious about server performance, and especially your Nginx environment, then go on over to Monitis today and start a free trial. One you see the benefits of the Monitis monitoring platform, you’ll be glad you did! You might also like What Is Synthetic Transaction Monitoring (And Who ... How often is your site closed for business? Updates: August 2009 Post navigation ← Older post Newer post →

All-in-one monitoring

Monitor your websites, servers, applications and more... anytime from anywhere. Start monitoring now No credit card required. Sign-up for a 15-day FREE trial.

Trending right now

   Colleges Increasingly Seek Notification Systems	
   Colleges Increasingly Seek Notification Systems
   How to make your website load faster?	
   How to make your website load faster?
   James Bond Meets IT Management: Monitis Announces Monitis Mobile





Referensi

Pranala Menarik