How To Install NGINX Web Server on Ubuntu 20.04 LTS and run on the browser!
NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.
Simply we can say that Nginx is just a kind of software that is used in web servers to serve concurrent requests.
Why it’s important?
- It was designed to handle a high volume of requests simultaneously
- It can cache static content without the need to fetch from the protected, origin server every time
- It is lightweight and flexibility of scaling
- It is commonly used as a reverse proxy and load balancer to manage incoming traffic and distribute the traffic
- 2.5 times faster than Apache and consume less memory
NGINX helps accelerate your IT infrastructure and application modernization efforts.
Let’s begin with installation of NGINX!
Step 1: Run the Software Update using the following command:
sudo apt update
It will ensure you have all the updates and necessary packages for Ubuntu.
Step 2: Install NGINX using the following command:
sudo apt install nginx
Cool, right? Now that NGINX is installed, you have to verify that it is running correctly.
Step 3: Configure your firewall settings with the following commands:
sudo ufw status
sudo ufw allow http
sudo ufw allow https
sudo systemctl start ufw
sudo ufw enable
sudo ufw status
Step 4: Run NGNIX and see the status NGNIX using the following command:
sudo systemctl start nginx
sudo systemctl status nginx
👏👏👏👏 Congratulations!! NGINX Server is active and running!!
There is a way, you can also check if NGINX server is running by using IP address on the web browser on the address bar (e.g. 52.26.212.75).
Learning from the Error:
Error 1 :
When I run the command sudo systemctl start nginx, it was giving me the attached error “job for nginx.service failed because the control process excited with error code..” “ failed to start A high performance web server ..”
Troubleshooting steps and finding solutions:
- run the command
sudo nginx -t
and checked the configuration file is ok and test is successful - run the command sudo lsof -i:80 to see which server is running on port 80. Found that apache2 is running on that port, I was not aware 😓. I have killed all the process for apache2 that I have installed before nginx
Then when I was running the command again
- sudo systemctl start nginx
- sudo systemctl status nginx
Finally, nginx started running 😅
Error 2:
When I wanted to see the NGINX server on the browser by typing localhost on the browser’s address bar, it was giving me the default browser that was for Apache server 😰. Hmm another troubleshoot ..
- Deleted browser history and tried again, didn’t work
- After doing a little research, found Nginx and Apache are referring to the
/var/www
HTML file - Run the attached command and refresh the page:
All issue has been fixed NGINX is now running on the browser 🆒
👏👏👏👏 Happy Learning!!
References:
https://whatismyipaddress.com/
https://askubuntu.com/questions/642238/why-do-i-still-see-an-apache-site-on-nginx
Note: If you think, this article is helpful 😄, please give me a clap 👏 to inspire me.
Please connect me on linkedin 👎
https://www.linkedin.com/in/aktersabina122/
Please follow me on Medium and Twitter 👎: