If you’ve ever hosted a website or web app, chances are you’ve heard of NGINX (pronounced “engine-x”). It’s one of the fastest, most reliable web servers out there — known for handling massive traffic loads while keeping your system light and responsive.
Whether you’re setting up a development server or hosting a production site, installing and configuring NGINX on Ubuntu is surprisingly straightforward. In this guide, we’ll walk you through every step — from installation to basic configuration — so you can get your web server up and running in no time.
What You’ll Need Before You Start
Before installing NGINX, make sure you have the following:
- A computer or VM running Ubuntu 22.04 (or later)
- Sudo privileges (you’ll need admin rights to install packages)
- A stable internet connection
That’s all! Once you’re set, open the terminal — it’s time to get to work.
Step 1: Update Your System Packages
First things first — it’s always a good idea to update your local package index. This ensures you’re installing the latest, most secure version of NGINX.
sudo apt update && sudo apt upgrade -y
This command updates your system packages and installs available upgrades. Once done, you’re ready to move on.
Step 2: Install NGINX on Ubuntu
Installing NGINX on Ubuntu is as simple as running a single command:
sudo apt install nginx -y
Ubuntu will automatically fetch NGINX from its official repository and install it along with any required dependencies.
Once installation completes, you can verify it by checking the version:
nginx -v
You should see output like:
nginx version: nginx/1.24.0 (Ubuntu)
That’s your confirmation that NGINX is successfully installed.
Step 3: Start and Enable the NGINX Service
Now that NGINX is installed, let’s start it up and make sure it runs automatically on boot.
sudo systemctl start nginx
sudo systemctl enable nginx
You can verify that the service is active with:
sudo systemctl status nginx
If it shows “active (running)”, congratulations — your web server is officially live!
Step 4: Verify NGINX Web Server in Your Browser
By default, NGINX serves a simple welcome page after installation. To check it:
- Open your web browser.
- Enter your server’s IP address (or
localhostif you’re running it locally):
http://localhost
You should see the “Welcome to NGINX!” page — that’s your server working perfectly.
If you’re running Ubuntu on a remote VPS, replace “localhost” with your server’s public IP address, like:
http://203.0.113.10
Step 5: Adjust Firewall Settings for NGINX
If you’re using UFW (Uncomplicated Firewall), you need to allow NGINX traffic through the firewall.
First, check available NGINX profiles:
sudo ufw app list
You’ll see something like:
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
To allow full access (both HTTP and HTTPS), run:
sudo ufw allow 'Nginx Full'
Now enable the firewall (if it’s not already enabled):
sudo ufw enable
And confirm the status:
sudo ufw status
You should now see rules allowing NGINX traffic.
Step 6: Configure a New Server Block (Virtual Host)
By default, NGINX stores site configuration files in the /etc/nginx/sites-available directory.
Let’s create a new one for your domain or project.
- Create a new configuration file:
sudo nano /etc/nginx/sites-available/mywebsite
- Add the following basic configuration:
server {
listen 80;
server_name mywebsite.com www.mywebsite.com;
root /var/www/mywebsite;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
- Save the file (
Ctrl + O, thenEnter, thenCtrl + Xto exit). - Create the web root directory:
sudo mkdir -p /var/www/mywebsite
- Add a sample HTML file to test:
echo "<h1>Hello from NGINX on Ubuntu!</h1>" | sudo tee /var/www/mywebsite/index.html
- Enable the new site:
sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
- Test the configuration for syntax errors:
sudo nginx -t
If everything’s fine, reload NGINX:
sudo systemctl reload nginx
Now, visit http://your_server_ip or your domain — and you’ll see your custom page served by NGINX!
Step 7: (Optional) Secure NGINX with SSL (Let’s Encrypt)
If your website is public-facing, you’ll definitely want to enable HTTPS for security.
You can do this easily using Certbot and Let’s Encrypt.
Install Certbot and the NGINX plugin:
sudo apt install certbot python3-certbot-nginx -y
Then run:
sudo certbot --nginx -d mywebsite.com -d www.mywebsite.com
Follow the prompts, and Certbot will automatically configure SSL and set up auto-renewal.
You can test the renewal process with:
sudo certbot renew --dry-run
Wrapping Up
And there you have it — your NGINX web server is up, configured, and running on Ubuntu!
You can now host static websites, PHP applications (with PHP-FPM), or even reverse proxy other apps.
NGINX’s performance, simplicity, and scalability make it one of the best choices for web hosting — whether you’re serving a small project or managing a high-traffic production server.
Once you’re comfortable with the basics, you can dive deeper into caching, load balancing, and advanced reverse proxy setups to unlock NGINX’s full potential.