<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Nginx_advanced_configuration</id>
	<title>Nginx advanced configuration - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Nginx_advanced_configuration"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Nginx_advanced_configuration&amp;action=history"/>
	<updated>2026-05-24T19:45:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Nginx_advanced_configuration&amp;diff=23944&amp;oldid=prev</id>
		<title>Cesar Chew at 17:31, 24 November 2014</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Nginx_advanced_configuration&amp;diff=23944&amp;oldid=prev"/>
		<updated>2014-11-24T17:31:01Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Cat|Nginx}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;slideshow style=&amp;quot;nobleprog&amp;quot; headingmark=&amp;quot;⌘&amp;quot; incmark=&amp;quot;…&amp;quot; scaled=&amp;quot;true&amp;quot; font=&amp;quot;Trebuchet MS&amp;quot; &amp;gt;&lt;br /&gt;
;title: Nginx advanced configuration&lt;br /&gt;
;author: Bernard Szlachta (NobleProg Ltd)&lt;br /&gt;
&amp;lt;/slideshow&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Overview ⌘===&lt;br /&gt;
* So far we have only configured virtual hosts&lt;br /&gt;
* Less commonly, you may need to configure global server options&lt;br /&gt;
* /etc/nginx/nginx.conf&lt;br /&gt;
&lt;br /&gt;
=== nginx architecture: Master Process ⌘===&lt;br /&gt;
* Reads configurations&lt;br /&gt;
* Handles sockets&lt;br /&gt;
* Opens log files&lt;br /&gt;
* Accepts signals (eg, to re-read configuration)&lt;br /&gt;
&lt;br /&gt;
=== nginx architecture: Worker process ⌘===&lt;br /&gt;
* Single thread&lt;br /&gt;
* Runs in an event loop&lt;br /&gt;
* Handles incoming connections&lt;br /&gt;
&lt;br /&gt;
=== Tuning worker processes ⌘===&lt;br /&gt;
* Rule of thumb: number of worker processes should be the same as number of cores&lt;br /&gt;
* If much time is spent blocked on io (see vmstat), worker processes should be increased further&lt;br /&gt;
&lt;br /&gt;
=== Worker connections ⌘===&lt;br /&gt;
* Number of concurrent connections available can be calculated:&lt;br /&gt;
 worker_processes * max_connections = max clients&lt;br /&gt;
* Default value is 1024; if necessary, typically can be raised with only positive effects.  4096 sensible&lt;br /&gt;
&lt;br /&gt;
=== Logging ⌘===&lt;br /&gt;
* Logging can be set per vhost or globally&lt;br /&gt;
* Log formats are defined in nginx.conf under http&lt;br /&gt;
&lt;br /&gt;
 log_format vhost &amp;#039;$host $remote_addr - $remote_user [$time_local]&amp;#039;&lt;br /&gt;
 &amp;#039;&amp;quot;$request&amp;quot; $status $body_bytes_sent &amp;#039;&lt;br /&gt;
 &amp;#039;&amp;quot;$http_referer&amp;quot; &amp;quot;$http_user_agent&amp;quot;&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
=== Rate limiting/DoS mitigation ⌘===&lt;br /&gt;
* DoS - denial of service&lt;br /&gt;
* Often takes the form of simply flooding the server with requests, hoping to saturate CPU resources and/or bandwidth&lt;br /&gt;
* nginx has a number of features to mitigate such an attack&lt;br /&gt;
&lt;br /&gt;
=== Limiting concurrent connections ⌘===&lt;br /&gt;
* nginx has a limit on the number of concurrent connections&lt;br /&gt;
* We can prevent a single IP from tying up too many&lt;br /&gt;
* NB - it is normal for a web browser to create up to 8 concurrent connections&lt;br /&gt;
&lt;br /&gt;
   limit_zone   one  $binary_remote_addr  10m;&lt;br /&gt;
   server {&lt;br /&gt;
     location / {&lt;br /&gt;
       limit_conn   one  8;&lt;br /&gt;
     }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
=== Preventing repeated connections from the same IP ⌘===&lt;br /&gt;
;&lt;br /&gt;
    limit_req_zone  $binary_remote_addr  zone=one:10m   rate=1r/s;&lt;br /&gt;
&lt;br /&gt;
    server {&lt;br /&gt;
      location /search/ {&lt;br /&gt;
        limit_req zone=one burst=5&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
* allows a user no more than 1 request per second on average, with bursts up to 5&lt;br /&gt;
&lt;br /&gt;
=== Limiting bandwidth usage ⌘===&lt;br /&gt;
&lt;br /&gt;
* By default, nginx will send as fast as it can&lt;br /&gt;
* nginx has a range of options for tuning this&lt;br /&gt;
&lt;br /&gt;
=== Limiting bandwidth usage - streaming ⌘===&lt;br /&gt;
* When streaming video/audio from a server, generally you want to give the client a reasonable buffer, then maintain this buffer&lt;br /&gt;
* Can be achieved with an initial fast connection, then rate limiting after&lt;br /&gt;
=== Streaming bandwidth limit example ⌘===&lt;br /&gt;
;&lt;br /&gt;
  location /streamfiles {&lt;br /&gt;
    limit_conn connections 1;&lt;br /&gt;
    limit_rate_after 16m;&lt;br /&gt;
    limit_rate 512k;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
* Limit each user to a single connection to files under this path&lt;br /&gt;
* Allow them to download the first 16MB at maximum speed&lt;br /&gt;
* After that, limit to 512KB (kiloBYTES, not kilobits) per second&lt;br /&gt;
&lt;br /&gt;
=== Media streaming ⌘===&lt;br /&gt;
&lt;br /&gt;
* nginx has support for pseudo-streaming for mp4 and flv files&lt;br /&gt;
* Client can seek to a specific location in the file&lt;br /&gt;
  location /flash-videos {&lt;br /&gt;
     flv;&lt;br /&gt;
   }&lt;br /&gt;
   location /mp4-videos {&lt;br /&gt;
     mp4;&lt;br /&gt;
   }&lt;/div&gt;</summary>
		<author><name>Cesar Chew</name></author>
	</entry>
</feed>