DEV Community

Cover image for How to Install NGINX on Ubuntu: Quick and Easy!
Hardik Gohil
Hardik Gohil

Posted on

How to Install NGINX on Ubuntu: Quick and Easy!

NGINX is the go-to web server for many developers—whether you need to serve web pages, act as a reverse proxy, or handle load balancing. It’s fast, reliable, and gets the job done without breaking a sweat. But before NGINX can work its magic, we need to get it installed. Let’s go through the steps of setting it up on your Ubuntu system.

Let’s dive in!

1. Update Your System First (Always! 🍀)

We all know that updating is the developer's equivalent of stretching before a run. Before installing NGINX, make sure your system is up to date. Open your terminal and run:

sudo apt update
Enter fullscreen mode Exit fullscreen mode
sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

This ensures you’re installing everything fresh and avoiding any version clashes.

2. Installing NGINX Like a Pro 💻

With the system updated, it’s time to install NGINX! Lucky for us, NGINX is in Ubuntu’s package manager. Just one simple command:

sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode

That’s it! NGINX is now on your system, ready to serve content and handle your web requests.

3. Start and Enable NGINX 🚀

After installation, let’s get NGINX running:

sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

Want NGINX to start automatically after every reboot? Let’s enable it too:

sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

With these commands, NGINX will stay running even after your server reboots—super handy for a web server!

4. Check if NGINX is Running Smoothly ✅

You might want to check if NGINX is working fine. To verify its status, run:

sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

You should see something like active (running) in green, which means everything is A-OK!

5. Firewall Settings (Optional but Wise) 🔥

If you have a firewall running (and you should!), make sure it allows web traffic. For HTTP (port 80), use:

sudo ufw allow 'Nginx HTTP'
Enter fullscreen mode Exit fullscreen mode

To allow both HTTP and HTTPS (ports 80 and 443):

sudo ufw allow 'Nginx Full'
Enter fullscreen mode Exit fullscreen mode

This will let NGINX do its thing without getting blocked by your firewall.

6. Test It! (The Fun Part) 🌍

The final step is to see NGINX in action. Open your browser and type in your server's IP address:

http://your_server_ip
Enter fullscreen mode Exit fullscreen mode

You should see the default NGINX welcome page, confirming that your web server is up and running!

Conclusion:
Boom! 🎉 NGINX is now up and running on your Ubuntu system. Whether you're building a simple static site or setting up a complex reverse proxy, you've got a powerful tool at your fingertips.

Thanks for reading, If you liked the post please share it and leave suggestions.


Connect With Me

Website: Hardik Gohil

Github: https://github.com/HardikGohilHLR

Linkedin: https://www.linkedin.com/in/hardikgohilhlr

Thanks ❤️

Top comments (0)