NGINX at its core is a reverse proxy server.
- high-performance web server
- can handle high-concurrency
- low resource usage
- faster static content delivery than Apache httpd
Installation on linux
sudo apt install nginx -y
To check if its running:
sudo systemctl status nginx
To run::
sudo systemctl start nginx
NGINX configuration file
Everything in an nginx configuration file is either a Directive or a Context
Directives
Directives are of 2 types
- Simple directives: it consists of the directive name and the space delimited parameters, like
listen
,return
and others, and are terminated by semicolons - Block directives: similar to simple directives, except that instead of ending with semicolons, they end with a pair of curly braces
{ }
enclosing additional instructions
A Block Directive capable of containing other directives inside it is called a context. There are 4 core contexts in NGINX
events { }
- this context is used for settings global configuration regarding how NGINX is going to handle requests on a general level. There can only be oneevents
context in a valid configuration filehttp { }
- this is used for defining configuration regarding how the server is going to handle HTTP and HTTPS requests, specifically. There can be only onehttp
context in a valid configuration fileserver { }
- this context is nested inside thehttp
context and used for configuring specific virtual servers within a single host. There can be multipleserver
contexts in a valid configuration file nested inside thehttp
context. Eachserver
context is considered a virtual hostmain { }
- it is the configuration file itself, anything written outside of the 3 previously mentioned contexts is on themain
context When a request reaches the nginx server, thelisten
directive is one of the ways to identify the correctserver
context to hit.