• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Optimizing Nginx (nginx.conf) on Cloud Server

By Abhishek Ghosh August 20, 2014 9:21 am Updated on October 17, 2014

Optimizing Nginx (nginx.conf) on Cloud Server

Advertisement

This guide for optimizing Nginx is related to the needed modification of the nginx.conf file on Cloud Server. Optimization will differ on Bare Metal. Practically we are using a multi tenant environment, even if on an instance there is Multi Core Processor, essentially they are virtual. There will be definite difference with physical multi-Core processor based computer vs. multi-CPU computer. Single tenant environments including bare metal, colocation server, dedicated server will have dedicated physically definable CPU and Motherboard.

 

Optimizing Nginx (nginx.conf) on Cloud Server : Where We Have Started From

 

You can start from our previous guide on how to install WordPress with Nginx on Rackspace Cloud Server, we have a helper video for installing nginx too. Those who are fully new with Nginx can read articles like Basics of nginx HTTP Server, Shifting WordPress from Apache to nginx Web Server, Reasons to Switch to Nginx From Apache on Cloud Server like articles. We recommend to use a different Server for running MySQL – application server is desirable to be different. This makes the things more easier. For testing purpose, you can use one server (2 GB, Performance 1 on Rackspace). 2 GB will offer 2 virtual cores. You must install Rackspace Cloud Monitoring Agent to check the load on CPU and RAM.

Optimizing Nginx (nginx.conf) on Cloud Server

 

Optimizing Nginx (nginx.conf) on Cloud Server

 

Nginx needs not much tweaking compared to PHP, Apache2 or MySQL. Kindly, do not use Nginx as proxy for Apache2 on the same server.

Advertisement

---

First, check again the guide how to install WordPress with Nginx on Rackspace Cloud Server for a quick recall, we have not done any modification of /etc/nginx/nginx.conf. Open it :

Vim
1
nano /etc/nginx/nginx.conf

The code block starts with :

Vim
1
2
3
4
5
6
worker_processes  8;
 
events {
    worker_connections  1024;
    multi_accept        on;
}

That worker_processes indicates number of CPU-core. For example, in 2 GB, it is 2. For a Multi CPU computer with multi core processors, the number will be simple addition. 2 Hexacore processor = 12 worker_processes. We can get this data by running this command :

Vim
1
grep processor /proc/cpuinfo | wc -l

Thankfully, we can set it to auto. We do not need to mention the raw number anymore.

Second variable is worker_connections, it is the number of clients that can be served per unit of time (second is the SI unit) multiplied by the number of cores. How we will know what worker_connections is set by the Operating System? We can run this command :

Vim
1
ulimit -n

If you run this on your 15″ MacBook Pro, it will return a value like 256. On Server with GNU Linux, usually it is 1024. Theoretically, what Nginx can handle as maximum of clients per unit time can be written as = worker_processes x worker_connections. It is, should be 1024 x 2 = 2048 in our case. This two directives are to prevent adverse situations, we will increase the capabilities via other directives. multi_accept makes to immediately accept as many connections Nginx can, it is related to the kernel socket setup. We keep it as ON. The parameter which is not present is worker_rlimit_nofile. Another absent parameter is epoll, this event-model is generally recommended to force to use. So our final thing is becoming :

Vim
1
2
3
4
5
6
7
8
9
10
worker_processes  auto;
 
events {
    worker_connections  2048;
    multi_accept        on;
    use                 epoll;
 
}
 
worker_rlimit_nofile 40000;

We should do a configtest before reloading :

Vim
1
2
3
4
5
6
7
nginx -t
# output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# or this command
/etc/init.d/nginx configtest
# will return [OK] if everything is fine

Now, do a reload and optionally restart :

Vim
1
2
service nginx reload
# service nginx restart

Next block starts with :

Vim
1
2
3
4
5
6
http {
    sendfile           on;
    tcp_nopush         on;
    tcp_nodelay        on;
    keepalive_timeout  15;
}

We only need to tweak the keepalive_timeout to keep a lesser number like 10. We will add a block here :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
open_file_cache          max=2000 inactive=20s;
open_file_cache_valid    60s;
open_file_cache_min_uses 5;
open_file_cache_errors   off;
 
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
client_body_timeout 12;
client_header_timeout 12;
 
large_client_header_buffers 2 1k;
send_timeout 10;

client_body_buffer_sizw handles the client buffer size – any POST actions sent to Nginx. client_header_buffer_size is similar but instead it handles the client header size only. For safety, 1K is usually a good value. client_max_body_size is the maximum allowed size for a client request, if exceeded, then Nginx will throw a 413 error. large_client_header_buffers is the maximum number and size of buffers for large client headers. client_body_timeout and client_header_timeout directives are for waiting after a request is sent. keepalive_timeout sets the timeout for keep-alive connections. Lower better for avowing delay with 404.

Up to this, our file will look like this :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
worker_processes  auto;
 
events {
    worker_connections  2048;
    multi_accept        on;
    use                 epoll;
 
}
 
worker_rlimit_nofile 40000;
 
http {
    sendfile           on;
    tcp_nopush         on;
    tcp_nodelay        on;
    keepalive_timeout  10;
    large_client_header_buffers 2 1k;
    send_timeout 10;
 
    open_file_cache          max=2000 inactive=20s;
    open_file_cache_valid    60s;
    open_file_cache_min_uses 5;
    open_file_cache_errors   off;
 
    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 8m;
    client_body_timeout 12;
    client_header_timeout 12;
 
# more stuffs here
 
}

We will make :

Vim
1
2
access_log off
error_log logs/error.log crit;

Access log is not required because you can track from other softwares. Error log becomes huge with time, we will log only critical errors. Last is gzip :

Vim
1
2
3
4
5
6
7
8
gzip             on;
gzip_comp_level  6;
gzip_min_length  1024;
gzip_proxied     expired no-cache no-store private auth;
gzip_vary on;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [6]";
gzip_http_version 1.1;

 

Optimizing Nginx (nginx.conf) on Cloud Server : Final Result

 

Finally it is becoming like :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
worker_processes  auto;
 
events {
    worker_connections  2048;
    multi_accept        on;
    use                 epoll;
 
}
 
worker_rlimit_nofile 40000;
 
http {
    sendfile           on;
    tcp_nopush         on;
    tcp_nodelay        on;
    keepalive_timeout  10;
    large_client_header_buffers 2 1k;
    send_timeout 10;
 
    open_file_cache          max=2000 inactive=20s;
    open_file_cache_valid    60s;
    open_file_cache_min_uses 5;
    open_file_cache_errors   off;
 
    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 8m;
    client_body_timeout 12;
    client_header_timeout 12;
 
    gzip             on;
    gzip_comp_level  6;
    gzip_min_length  1024;
    gzip_vary on;
    # gzip_proxied any;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_disable "msie6";
    gzip_http_version 1.1;
 
# more stuffs here
 
}

Test with :

Vim
1
2
3
nginx -t
# or
/etc/init.d/nginx configtest

Then restart :

Vim
1
2
service nginx reload
# service nginx restart

If there is any repeat code, please let us know. There is a thing name “server_token”, it is set to off by default but kept commented out. Just make it active for security reasons. As for syntax, only worker_processes and worker_rlimit_nofile are outside { second brackets }.

Tagged With @yahoo @gmail @hotmail @aol , nano /etc/nginx/nginx conf , http://etc/nginx/nginx conf , nano -w /etc/nginx/nginx conf , optimize nginx for windows , television1tv

This Article Has Been Shared 638 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Optimizing Nginx (nginx.conf) on Cloud Server

  • SoundCloud : What is SoundCloud and How to Use the Service

    SoundCloud is an online platform for musician and audio enthusiasts for distributing audio files. It serves as co-operation platform for the audiophiles.

  • Carrier Cloud : The Basic Concept

    Carrier Cloud derived from the terminology used in telecommunication – carrier class.Carrier Class are engineered to meet or exceed high availability standards.

  • Ubuntu Cloud Guest Instance : Our Test Drive

    Ubuntu Cloud Guest Instance is actually hosted on Amazon EC2 and a kind of ready made solution as PaaS is provided by Canonical for free of cost to test.

  • Installing an Advanced Pastebin on Rackspace Cloud Sites

    Installing an Advanced Pastebin on Rackspace Cloud Sites can be done with Stikked, adding Twitter Bootstrap like interface to make it more attracting, light.

  • Cloud Security Infrastructure Requires Transparency

    Cloud security infrastructure includes validated and scalable shared infrastructure based on computer, network and storage solutions usually from different vendors.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Cyberpunk Aesthetics: What’s in it Special January 27, 2023
  • How to Do Electrical Layout Plan for Adding Smart Switches January 26, 2023
  • What is a Data Mesh? January 25, 2023
  • What is Vehicular Ad-Hoc Network? January 24, 2023
  • Difference Between Panel Light, COB Light, Track Light January 21, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Optimizing Nginx (nginx.conf) on Cloud Server," in The Customize Windows, August 20, 2014, January 29, 2023, https://thecustomizewindows.com/2014/08/optimizing-nginx-nginx-conf-cloud-server/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT