NGINX Web Server Installation and Configuration in Ubuntu
NGINX is a feature rich and high-performance software which is mainly used for Web Server. NGINX can also be used as a proxy server, load balancer, mail proxy and HTTP Cache Server. NGINX is a free and open-source software and can be run on Linux, Windows. macOS and other operating systems.
NGINX is a single-thread based application. So, it can handle unlimited client requests using asynchronous technique. NGINX processes highly efficient run loops in a single-thread process called workers. Workers accept new requests from a shared listen socket and execute highly efficient run loops inside each worker to process thousands of requests.
NGINX is so essential for those who are involved in web technology. NGINX can be used for small, medium or for large scale application. NGINX is well performed on Linux environment. In this article we will learn how to install and configure NGINX Web Server in Ubuntu Server.
NGINX Installation and Basic Configuration
NGINX works smoothly with Ubuntu Server. If we have Ubuntu Server installed on our physical server or virtual server, we can easily install NGINX Web Server in Ubuntu Server. But before going to start NGINX installation, we should update and upgrade our Ubuntu Server. For this, run the following command from Ubuntu Command Prompt.
- sudo apt update
- sudo apt upgrade
Our Ubuntu Server is now up to date. We will now install NGINX Web Server in Ubuntu Server with the following command.
- sudo apt install nginx -y
The nginx service will be installed and the service will be active and running automatically. So, if we type the IP Address of our Ubuntu Server in any Web Broser, we will get the following output.
If we get the above output, our NGINX Web Server is up and running. We can check NGINX service status from Ubuntu command prompt using the following command.
- sudo systemctl status nginx
If we change any configuration of our NGINX Web Server, we can load the new configuration using the following command.
- sudo systemctl reload nginx
It is also possible to reload new configuration restarting the NGINX service using the following command.
- sudo systemctl restart nginx
If we need to stop nginx service at any emergency reason, we can run the following command to stop the nginx web server.
- sudo systemctl stop nginx
Again, if we need to start the nginx service, just run the following command to start the stopped nginx service.
- sudo systemctl start nginx
If we want to start nginx service automatically after restart the Ubuntu Server, issue the following command.
- sudo systemctl enable nginx
We can disable auto start using the following command although.
- sudo systemctl disable nginx
HTTP and HTTPS services are run on 80 and 443 port accordingly. So, we have to allow 80 port and 443 port from our firewall. Otherwise, the expected output will not be shown by the NGINX Web Server.
The default configuration file of NGINX is located at /etc/nginx/sites-available directory. The name of the default configuration file is default. So, if we open the default configuration file with any text editor like vim, we will get the following code in the file.
- vim /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
In the default configuration file, we will get a server block and its listening port. Here, we will also find the document root folder and the index file name.
If we wish, we can modify our default configuration file or can keep the default configuration and can change our webpage according to our requirements.
If you face any confusion to follow commands, feel free to watch the below video on NGINX installatiion and configuration.
How to install and configure NGINX Web Server in Ubuntu Server has been discussed in this article. I hope, you will now be able to setup NGINX Web Server in Ubuntu environment. However, if you face any confusion to install and configure NGINX Web Server. Free to discuss in comment or contact me from Contact page. I will try my best to stay with you.
Why not a Cup of COFFEE if the solution?