NGINX is an open-source web server written in C and can also be used as a reverse proxy and a load balancer. This class Is an introduction to NGINX, by the end of this class you will be able to understand the fundamentals of NGINX and spin up your own instance and even secure it with a legitimate certificate.
NGINX is an open-source web server written in C and can also be used as a reverse proxy and a load balancer. This class Is an introduction to NGINX, by the end of this class you will be able to understand the fundamentals of NGINX and spin up your own instance and even secure it with a legitimate certificate.
Here are the topics that I will discuss:
What is NGINX?
NGINX Use Cases
Layer 4 and Layer 7 Proxying in Nginx
NGINX Timoouts
Example
Install Nginx (mac)
Nginx as a Web Server
Static content
Regular expression in NGINX
proxy_pass
Nginx as a Layer 7 Proxy
Proxy to 4 backend NodeJS services (docker)
IP_Hash load balancing
Split load to multiple backends (app1/app2)
Block certain requests (/admin)
NGINX as a Layer 4 Proxy
Create DNS record
Enable HTTPS on NGINX (lets encrypt)
Enable TLS 1.3 on NGINX
Enable HTTP/2 on NGINX
A small blurb about NGINX
NGINX is one of a handful of servers written to address the C10K problem. Unlike traditional servers, NGINX doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load. Even if you don’t expect to handle thousands of simultaneous requests, you can still benefit from NGINX’s high-performance and small memory footprint. NGINX scales in all directions: from the smallest VPS all the way up to large clusters of servers.
Syntax:
client_header_timeout time;
Default:
client_header_timeout 60s;
Context:
http, server
Defines a timeout for reading client request header. If a client does not transmit the entire header within this time, the request is terminated with the 408 (Request Time-out) error.
Syntax:
client_body_timeout time;
Default:
client_body_timeout 60s;
Context:
http, server, location
Defines a timeout for reading client request body. The timeout is set only for a period between two successive read operations, not for the transmission of the whole request body. If a client does not transmit anything within this time, the request is terminated with the 408 (Request Time-out) error.
Syntax:
send_timeout time;
Default:
send_timeout 60s;
Context:
http, server, location
Sets a timeout for transmitting a response to the client. The timeout is set only between two successive write operations, not for the transmission of the whole response. If the client does not receive anything within this time, the connection is closed.
Syntax:
keepalive_timeout timeout [header_timeout];
Default:
keepalive_timeout 75s;
Context:
http, server, location
The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The zero value disables keep-alive client connections. The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field. Two parameters may differ.
The “Keep-Alive: timeout=time” header field is recognized by Mozilla and Konqueror. MSIE closes keep-alive connections by itself in about 60 seconds.
Syntax:
lingering_timeout time;
Default:
lingering_timeout 5s;
Context:
http, server, location
When lingering_close is in effect, this directive specifies the maximum waiting time for more client data to arrive. If data are not received during this time, the connection is closed. Otherwise, the data are read and ignored, and nginx starts waiting for more data again. The “wait-read-ignore” cycle is repeated, but no longer than specified by the lingering_time directive.
Syntax:
resolver_timeout time;
Default:
resolver_timeout 30s;
Context:
http, server, location
Sets a timeout for name resolution, for example:
resolver_timeout 5s;
Syntax:
proxy_connect_timeout time;
Default:
proxy_connect_timeout 60s;
Context:
http, server, location
Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.
Syntax:
proxy_send_timeout time;
Default:
proxy_send_timeout 60s;
Context:
http, server, location
Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.
Syntax:
proxy_read_timeout time;
Default:
proxy_read_timeout 60s;
Context:
http, server, location
Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.
Syntax:
proxy_next_upstream_timeout time;
Default:
proxy_next_upstream_timeout 0;
Context:
http, server, location
This directive appeared in version 1.7.5.
Limits the time during which a request can be passed to the next server. The 0 value turns off this limitation.
Syntax:
keepalive_timeout timeout;
Default:
keepalive_timeout 60s;
Context:
upstream
This directive appeared in version 1.15.3.
Sets a timeout during which an idle keepalive connection to an upstream server will stay open.
Find the code here https://github.com/hnasr/javascript_playground/tree/master/docker
OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.
Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.
Find this site helpful? Tell a friend about us.
We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.
Your purchases help us maintain our catalog and keep our servers humming without ads.
Thank you for supporting OpenCourser.