Setting Up and Managing Nginx on Ubuntu: A Beginner’s Guide

Shaon Majumder
2 min readMar 5, 2024

--

Hey there, web enthusiasts! Welcome to our journey of setting up Nginx on an Ubuntu server — your ticket to hosting websites with lightning-fast performance and unbeatable scalability. Nginx is like the superhero of web servers, ready to handle your website’s traffic like a pro. Buckle up, and let’s dive into the world of Nginx!

Prerequisites: Before we embark on this adventure, make sure you’ve got:

  • A trusty Ubuntu server with a regular, non-root user having sudo privileges.

Step 1 — Installing Nginx: Let’s kick things off by installing Nginx straight from the Ubuntu repositories. Pop open your terminal and fire up these commands:

sudo apt update
sudo apt install nginx

Hit ‘Y’ when prompted — we’re bringing Nginx and its entourage of dependencies to your server.

Step 2 — Adjusting the Firewall: We need to let the firewall know about our new buddy Nginx. Run these commands to make the necessary adjustments:

sudo ufw allow 'Nginx HTTP'
sudo ufw enable
sudo ufw status

We’re opening the gates for HTTP traffic (port 80) and ensuring UFW (Uncomplicated Firewall) is on board with the plan. Check the status to confirm everything’s good to go.

Step 3 — Checking Your Web Server: Now that Nginx is all set up, let’s make sure it’s up and running. Fire this command to see what Nginx is up to:

systemctl status nginx

You should see Nginx flexing its muscles — active and ready for action!

To double-check that Nginx is serving pages like a champ, open your favorite browser and head over to http://localhost. You’ll be greeted by the default Nginx landing page, signaling that everything’s working as it should.

Step 4 — Managing the Nginx Process: Time to master some Nginx kung-fu moves! Here are the commands to control the Nginx service:

#Stop the web server:
sudo systemctl stop nginx

#Start the web server:
sudo systemctl start nginx

#Restart the web server:
sudo systemctl restart nginx

#Reload configuration without dropping connections:
sudo systemctl reload nginx

#Disable automatic startup at boot:
sudo systemctl disable nginx

#Enable automatic startup at boot:
sudo systemctl enable nginx

You’re now equipped with the power to wield Nginx like a true web warrior!

Conclusion: Hats off to you, fearless adventurer! You’ve conquered the realm of Nginx on your Ubuntu server. With Nginx by your side, you’re ready to conquer the web and host your websites with unmatched speed and reliability. Now go ahead, unleash your creativity, and let Nginx elevate your web hosting game to new heights!

--

--

Shaon Majumder
Shaon Majumder

Written by Shaon Majumder

Software Engineer | Author | Data Scientist

No responses yet