Nginx is an open source web server that is similar to Apache, but very light weight. Nginx is both web server and reverse proxy server.
Nginx is pronounced as “Engine X”.
Nginx is short form after you remove both the e’s from “Engine X”.
- It serves static and index files
- Reverse proxy with caching
- Supports SSL
- Simple load balancing with fault tolerance
- Both name-based and ip-based virtual server can be configured
- HTTP basic authentication
- Supports rewrite module
- Supports gzip, XSLT, SSI and image resizing filters
- All the main mail proxy server features are supported
Nginx is available in Ubuntu’s default repositories, so the installation is rather straight forward.
We will update our local package index so that we have access to the most recent package listings. Afterwards, we can install N
- sudo apt-get update
- sudo apt-get install nginx
After accepting the procedure,
apt-get will install Nginx and any required dependencies to your server.
Adjust the Firewall
There are three profiles available for Nginx:
- Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
- Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)
- Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)
Enable by using the Uncomplicated Firewall (ufw)
- sudo ufw allow ‘Nginx HTTP’
Note:- The Uncomplicated Firewall (ufw) is a frontend for iptables and is particularly well-suited for host-based firewalls. ufw provides a framework for managing netfilter, as well as a command-line interface for manipulating the firewall.
Verify the change:
- sudo ufw status
Check your Web Server
sudo systemctl status nginx
For your public IP address as seen from another location on the Internet:
- sudo apt-get install curl
- curl -4 icanhazip.com
When you have your server’s IP address or domain, enter it into your browser’s address bar:
You should see the default Nginx landing page…
Manage the Nginx Process
Some basic management commands.
To stop your web server:
- sudo systemctl stop nginx
To start the web server when it is stopped:
- sudo systemctl start nginx
To stop and then start the service again:
- sudo systemctl restart nginx
If you are simply making configuration changes, Nginx can often reload without dropping connections:
- sudo systemctl reload nginx
By default, Nginx is configured to start automatically when the server boots. You can disable:
- sudo systemctl disable nginx
To re-enable the service to start up at boot:
- sudo systemctl enable nginx
To view the current version of Nginx, do the following:
- ./nginx -v
To debug issues, view the error.log and access.log files located under /usr/local/nginx/logs
- ls /usr/local/nginx/logs/
Important Nginx Files and Directories
- /var/www/html: The actual web content (for all the web server), which by default only consists of the default Nginx page you saw earlier, is served out of the /var/www/html directory. This can be changed by altering Nginx configuration files.
- /etc/nginx: The nginx configuration directory. All of the Nginx configuration files inside this directory.