You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/books/web_services/022-web-servers-nginx.md
+42-42Lines changed: 42 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -25,42 +25,42 @@ In this chapter, you will learn about the web server Nginx.
25
25
26
26
### Generalities
27
27
28
-
**Nginx** is a **free HTTP web server under BSD license**. It was first developed in Russia in 2002 by Igor Sysoev. In addition to the standard features of a web server, Nginx provides a **reverse proxy** for the **HTTP** protocol, as well as a proxy for the **POP** and **IMAP** messaging protocols.
28
+
**Nginx** is a **free HTTP web server under BSD license**. It was first developed in Russia in 2002 by Igor Sysoev. In addition to the standard features of a web server, Nginx provides a **reverse proxy** for the **HTTP** protocol, and a proxy for the **POP** and **IMAP** messaging protocols.
29
29
30
-
The development of the nginx server is a response to the **C10K** problem: supporting 10,000 concurrent connections (common on the modern web) is a real challenge for web servers.
30
+
The development of the Nginx server is a response to the **C10K** problem. That is, supporting ten thousand concurrent connections (common on the modern web). It is a real challenge for web servers.
31
31
32
32
Commercial support is available from Nginx Inc.
33
33
34
34
The server's internal architecture enables **very high performance** with **low memory consumption** compared to the Apache web server in particular.
35
35
36
-
Modules complementing the basic functions of the nginx kernel are compile-time bound: they cannot be activated/deactivated on the fly.
36
+
Modules complementing the basic functions of the Nginx kernel are compile-time bound. Meaning activation or deactivation cannot happen dynamically.
37
37
38
-
Server processes are controlled by a master process, making it possible to **modify configuration or update software without stopping service**.
38
+
Control of server processes is with a master process, making it possible to **modify configuration or update software without stopping the service**.
39
39
40
40
Nginx has a significant market share of 28% on the busiest sites on the market, just behind Apache (41%).
41
41
42
42
#### Features
43
43
44
44
Nginx offers the following basic functions:
45
45
46
-
* Hosting of static web pages;
47
-
* Automatic index page generation;
48
-
* Accelerated reverse proxy with cache;
49
-
* Load balancing;
50
-
* Fault tolerance;
51
-
* Cached support for FastCGI, uWSGI, SCGI and memcached cache server;
52
-
* Various filters for gzip, xslt, ssi, image transformation, ...
53
-
* Support for SSL/TLS and SNI;
54
-
* HTTP/2 support.
46
+
* Hosting of static web pages
47
+
* Automatic index page generation
48
+
* Accelerated reverse proxy with cache
49
+
* Load balancing
50
+
* Fault tolerance
51
+
* Cached support for FastCGI, uWSGI, SCGI and memcached cache server
52
+
* Various filters for gzip, xslt, ssi, image transformation, and more
|`user`| Defines the process owner `user` and `group`. If the group is not specified, the group with the same name as the user is used. |
129
-
|`worker_processes`| Defines the number of processes. The optimum value depends on many factors, such as the number of CPU cores, hard disk specifications, etc. In case of doubt, the nginx documentation suggests a starting value equivalent to the number of CPU cores available (the auto value will try to determine this). |
129
+
|`worker_processes`| Defines the number of processes. The optimum value depends on many factors, such as the number of CPU cores, hard disk specifications, etc. In case of doubt, the Nginx documentation suggests a starting value equivalent to the number of CPU cores available (the auto value will try to determine this). |
130
130
|`pid`| Defines a file to store the pid value. |
131
131
|`worker_connections`| Sets the maximum number of simultaneous connections a worker process can open (to the client and to mandated servers). |
132
132
|`tcp_nopush`|`tcp_nopush` is inseparable from the sendfile option. It is used to optimize the quantity of information sent at a single time. Packets are only sent when they have reached their maximum size. |
133
133
|`tcp_nodelay`| Activating `tcp_nodelay` forces data contained in the socket to be sent immediately, regardless of packet size, which is the opposite of what `tcp_nopush` does. |
134
-
|`sendfile`| Optimize the sending of static files (this option is not required for a proxy-inverse configuration). If sendfile is enabled, nginx ensures that all packets are completed before they are sent to the client (thanks to `tcp_nopush`). When the last packet arrives, nginx disables `tcp_nopush` and forces data to be sent using `tcp_nodelay`. |
134
+
|`sendfile`| Optimize the sending of static files (this option is not required for a proxy-inverse configuration). If sendfile is enabled, Nginx ensures that all packets are completed before they are sent to the client (thanks to `tcp_nopush`). When the last packet arrives, Nginx disables `tcp_nopush` and forces data to be sent using `tcp_nodelay`. |
135
135
|`keepalive_timeout`| maximum time before closing an inactive connection. |
136
136
|`types_hash_max_size`| Nginx maintains hash tables containing static information. Set the maximum size of the hash table. |
137
137
|`include`| Include another file or files that match the template provided in the configuration. |
|`gzip`| The ngx_http_gzip_module is a filter that compresses data transmitted in gzip format. |
144
144
|`gzip_disable`| Disable gzip based on a regular expression. |
145
145
146
-
The nginx configuration is structured as follows:
146
+
The structure of the Nginx configuration is:
147
147
148
148
```text
149
149
# global directives
@@ -157,14 +157,14 @@ http {
157
157
158
158
# Configure the first server listening on port 80
159
159
server {
160
-
listen 80 default_server;
161
-
listen [::]:80 default_server;
162
-
root /var/www/html;
163
-
index index.html index.htm;
164
-
server_name _;
165
-
location / {
166
-
try_files $uri $uri/ =404;
167
-
}
160
+
listen 80 default_server;
161
+
listen [::]:80 default_server;
162
+
root /var/www/html;
163
+
index index.html index.htm;
164
+
server_name _;
165
+
location / {
166
+
try_files $uri $uri/ =404;
167
+
}
168
168
}
169
169
}
170
170
@@ -191,9 +191,9 @@ mail {
191
191
192
192
### https configuration
193
193
194
-
To configure an https service, you need to add a server block, or modify an existing server block (a server block can listen on both port 443 and port 80).
194
+
To configure an HTTPS service, you need to add a server block, or modify an existing server block. A server block can listen on both port 443 and port 80.
195
195
196
-
This block can, for example, be added to the new `/etc/nginx/conf.d/default_https.conf` file:
196
+
You can add this block, for example, to the new `/etc/nginx/conf.d/default_https.conf` file:
197
197
198
198
```bash
199
199
server {
@@ -210,7 +210,7 @@ server {
210
210
}
211
211
```
212
212
213
-
or the default server can be modified to support https:
213
+
or you can modify the default server to support HTTPS:
214
214
215
215
```bash
216
216
server {
@@ -226,9 +226,9 @@ server {
226
226
227
227
### Log management
228
228
229
-
The `error_log` directive is used to configure error logs.
229
+
You can configure the `error_log` directive for error logs.
230
230
231
-
Syntax of the error_log directive:
231
+
Syntax of the `error_log` directive:
232
232
233
233
```bash
234
234
error_log file [level];
@@ -238,15 +238,15 @@ The first parameter defines a file to receive error logs.
238
238
239
239
The second parameter determines the log level: debug, info, notice, warn, error, crit, alert or emerg (see syslog chapter of our admin guide).
240
240
241
-
Logs can be sent to syslog using the “syslog:” prefix.
241
+
The function of sending logs to syslog is with the “syslog:” prefix.
Reverse proxy functionality is provided by the `ngx_http_upstream_module`. It lets you define groups of servers which are then called by the `proxy_pass` or `fastcgi_pass` directives, `memcached_pass`, etc.
249
+
Reverse proxy functionality is with the `ngx_http_upstream_module`. It lets you define groups of servers which are then called by the `proxy_pass` or `fastcgi_pass` directives, `memcached_pass`, and more.
250
250
251
251
Example of a basic configuration, which distributes the load 2/3 to the first server and 1/3 to the second application server:
252
252
@@ -263,7 +263,7 @@ Example of a basic configuration, which distributes the load 2/3 to the first se
263
263
}
264
264
```
265
265
266
-
Servers can be declared as backups:
266
+
You can declare servers as backups:
267
267
268
268
```bash
269
269
upstream frontservers {
@@ -273,7 +273,7 @@ Servers can be declared as backups:
273
273
}
274
274
```
275
275
276
-
The server directive accepts a number of arguments:
276
+
The server directive accepts many arguments:
277
277
278
278
*`max_fails=numberofattempts`: sets the number of connection attempts that must fail during the time period defined by the `fail_timeout` parameter for the server to be considered unavailable. Default value is 1, 0 disables functionality.
279
279
*`fail_timeout=time`: sets the time during which a defined number of connections will cause the server to be unavailable, and sets the period of time during which the server will be considered unavailable. The default value is 10 seconds.
0 commit comments