nginx Getting started with nginx

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

NGINX is pronounced like "engine x" and is commonly used as a high performance server for protocols HTTP, HTTPS, SMTP, POP3 and IMAP. It can be used as a reverse proxy server, HTTP cache or load balancing.

It is an open source project with source available here.

Versions

VersionOriginal release dateLatest versionStatusRelease Date
0.52006-12-040.5.38Legacy2009-09-14
0.62007-06-140.6.39Legacy2009-09-14
0.72008-05-190.7.69Legacy2011-07-19
0.82009-06-020.8.55Legacy2011-07-19
1.02011-04-121.0.15Legacy2012-04-12
1.22012-04-231.2.9Legacy2013-05-13
1.42013-04-241.4.7Legacy2014-03-18
1.62014-04-241.6.3Legacy2015-04-07
1.82015-04-211.8.1Legacy2016-01-26
1.92015-04-281.9.15Legacy2016-04-19
1.102016-04-261.10.3Stable2016-05-31
1.112016-05-241.11.9Mainline2016-07-26

Installation and setup

Nginx is a Web server used to serve HTTP requests over the Internet.

Nginx is available on Linux, Windows and other OSes as direct download, and can also be built from source. For detailed instructions see Nginx official reference.

ubuntu/debian

nginx stable version is available in official repo, it can be installed using

sudo apt-get install nginx
 

It will install and configure system startup files, but if you need latest version, you may need to add official ppa.

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
 

above instructions will install latest stable edition.

Nginx inside

One of the biggest appeals of Nginx is the difference in how it works internally as compared to the other popular servers, specially Apache.

Servers are busy programs as they have to serve requests from multiple clients. The more requests a server can successfully serve per second, the better.

Nginx works on a concurrency paradigm known as Asynchronous IO.

In a conventional server, one thread is dedicated to one request. This means, once a thread takes up a request, it is effectively unavailable for other requests. But in reality, a thread could do a lot better by accepting a bunch of requests and serving them simultaneously. Asynchronous IO is what enables this.

Nginx, therefore with its Asynchronous IO architecture, can serve many requests within one thread.

Another good thing about Nginx is its relatively leaner resource footprint. Compared to Apache, Nginx is less resource heavy, and this makes it suitable to cloud servers what tend not to be very powerful.

There are certainly other Async IO server out there, but Nginx is the most well supported among all in terms of pluginx (aka Nginx Modules).

Nginx installation on Debian and Debian-based distros like Ubuntu

Run command below to install nginx.

sudo apt-get install nginx
 

By default, Nginx automatically starts when it is installed. You can access the default Nginx landing page to confirm that the software is running properly by visiting your server's domain name or public IP address in your web browser.

but if you need latest version, you may need to add official ppa.

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
 

Reload NGINX configuration file

As a root user:

sudo nginx -s reload
 

Ubuntu 14.04 example

sudo service nginx reload
 

Ubuntu 16.04 example

sudo systemctl reload nginx
 

Before reloading, it is a good idea to check config for syntax errors:

sudo nginx -t
 

Or

sudo service nginx configtest
 

Restart NGINX

As a root user:

nginx -s restart
 

Ubuntu example

sudo service nginx restart
 

Shutdown NGINX

Run as a root user.

Fast shutdown:

nginx -s stop
 

Graceful shutdown:

nginx -s quit
 

Test if your changes in nginx.config are valid

Ubuntu 14.04 example

sudo nginx -t 
 


Got any nginx Question?