When I first started using Ubuntu for my websites, I didn’t know what a “web server” was. Maybe you feel the same way. That’s okay. We all start somewhere.
In this post, I’ll walk you through how to install Nginx on an Ubuntu server. It’s not hard. If you can follow a recipe, you can do this too.
Let’s get started.
What is Nginx?
Nginx (say it like “engine-x”) is a web server. It’s like a waiter at a restaurant. When someone visits your website, Nginx brings them the page.
Why use Nginx? It’s fast, light, and doesn’t use a lot of memory. That makes it perfect for small servers or websites just starting out. I’ve used it for years and never had big problems.
Do you want to host a blog? A portfolio? An online store? Nginx can help.
What You Need Before You Start
You’ll need a few things ready before installing Nginx:
- A computer or server with Ubuntu installed (any recent version is okay, like Ubuntu 20.04 or 22.04).
- Access to that server using SSH (if it’s a remote server).
- A user account with sudo rights (so you can run commands as an admin).
- A little bit of patience.
If you’re missing any of these, it’s better to pause and set them up first.
Step 1: Update Your Server
Whenever I start working on a new Ubuntu server, the first thing I do is update it.
Here’s how:
sudo apt update
sudo apt upgrade
This makes sure everything is fresh. Old software can cause bugs. Trust me, I’ve learned that the hard way.
The commands above may take a few minutes. Just let them run. If you see questions, read them and answer carefully.
Step 2: Install Nginx
Now let’s install Nginx. It’s in Ubuntu’s official package list, so it’s easy.
Run this command:
sudo apt install nginx
You might be asked to confirm. Type Y
and hit Enter.
That’s it. Nginx will be installed in a minute or two.
Want to check if it’s running? Try this:
sudo systemctl status nginx
If it says “active (running),” you’re good.
Step 3: Test If Nginx Works
Now let’s check with a web browser.
If you’re on the server, open your browser and go to:
http://localhost
If you’re on a different computer, type your server’s IP address in the browser. For example:
http://192.168.1.10
You should see a welcome page from Nginx. It says “Welcome to Nginx!” in big letters.
Did you see it? That means Nginx is running and ready.
Step 4: Understand the Folder Structure
One thing that confused me at first was where to put my website files. Let me explain.
Nginx’s default web folder is:
/var/www/html
That’s where you place your website files, like HTML or PHP files.
You can test it by creating a simple file:
echo "Hello from Nginx" | sudo tee /var/www/html/index.html
Then reload your browser. You should see your new message.
Here are some key folders and files:
/etc/nginx/nginx.conf
: The main configuration file./etc/nginx/sites-available/
: Place to store site configs./etc/nginx/sites-enabled/
: Where active configs are linked./var/www/html/
: Default website files go here.
Once you learn these paths, things get easier.
Step 5: Control the Nginx Service
Sometimes you’ll want to restart Nginx after making changes. Here are some commands I use a lot:
- Start Nginx:
sudo systemctl start nginx
- Stop Nginx:
sudo systemctl stop nginx
- Restart Nginx:
sudo systemctl restart nginx
- Reload Nginx without stopping:
sudo systemctl reload nginx
- Enable Nginx to start on boot:
sudo systemctl enable nginx
- Disable Nginx from auto-starting:
sudo systemctl disable nginx
I keep these commands in a sticky note on my desktop. You might want to do the same.
Step 6: Allow Nginx Through the Firewall
If your server has a firewall (like UFW), it might block Nginx. Let’s fix that.
First, check if UFW is enabled:
sudo ufw status
If it says “inactive,” you’re okay for now.
If it says “active,” you need to allow Nginx:
sudo ufw allow 'Nginx Full'
This opens ports 80 (HTTP) and 443 (HTTPS). Now people can visit your site.
What’s Next?
Now that you have Nginx running, what do you want to do with it?
Maybe you want to:
- Serve a static site (like a portfolio).
- Run WordPress or another app with PHP and MySQL.
- Use Nginx as a reverse proxy for Node.js or Python apps.
There’s a lot you can do. Nginx is flexible. That’s why so many people use it.
Here’s a short list of ideas you can try next:
- Set up a custom domain name to point to your server.
- Enable SSL with Let’s Encrypt so your site uses HTTPS.
- Learn about Nginx server blocks (like virtual hosts).
- Tune performance using caching and gzip.
Why I Like Nginx
I’ve tried Apache, Lighttpd, and others. But I keep coming back to Nginx.
Why?
It’s simple to install. Easy to configure. And it rarely crashes.
When I first installed Nginx on a tiny $5/month server, it handled my blog just fine. Later, I helped a friend host a photo site. Nginx worked there too.
I’ve even used it to host an app for 10,000 users. It didn’t break a sweat.
If you’re starting out, Nginx is a great choice. You won’t need to babysit it.
Final Thoughts
Installing Nginx on Ubuntu may sound tricky at first, but it’s really just a few commands. Once it’s running, you have a strong foundation for any website.
If something breaks, don’t panic. Read the error message. Google it. You’ll learn fast.
I believe anyone can manage their own server. Including you.
So, what will you build with Nginx?
If you get stuck or want to ask me something, leave a comment. I’d be happy to help.