On This Page
- Step 1: Connect to Your Server via SSH
- Step 2: Update System Packages
- Step 3: Install Nginx
- Step 4: Navigate to Sites Configuration Directory
- Step 5: Create a Site Configuration File
- Step 6: Enable the Site
- Step 7: Test Configuration and Restart Nginx
- Step 8: Create Website Directory and Index File
- Step 9: Test Your Website
- See Also
How to Configure Nginx on Port 80
This guide walks you through setting up the Nginx web server on a Linux-based system (Ubuntu/Debian) to serve a static website on port 80. You'll learn how to install Nginx, create a site configuration, enable it, and test your setup.
Step 1: Connect to Your Server via SSH
Open your terminal and connect to your server as the root user:
ssh root@yourdomain.com
Replace yourdomain.com
with your actual domain or server IP address.
Step 2: Update System Packages
Ensure your package list and installed software are up to date:
sudo apt update
sudo apt upgrade -y
Step 3: Install Nginx
Install the Nginx web server using the package manager:
sudo apt install nginx -y
Step 4: Navigate to Sites Configuration Directory
Nginx supports hosting multiple websites using separate configuration files. These are stored in /etc/nginx/sites-available
. Move into this directory:
cd /etc/nginx/sites-available
Step 5: Create a Site Configuration File
Create a new configuration file named after your domain:
sudo nano yourdomain.com
Add the following configuration (replace yourdomain.com
with your actual domain):
server {
listen 80;
server_name yourdomain.com;
root /var/www/yourdomain.com;
index index.html;
}
listen 80;
� Listens for HTTP traffic on port 80.server_name
� Defines the domain name this server block responds to.root
� Specifies the directory where website files are stored.index
� Sets the default file to serve when a user visits the root URL.
Step 6: Enable the Site
Files in sites-available
are not automatically used by Nginx. To activate the site, create a symbolic link to sites-enabled
:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
This approach avoids duplication and allows you to manage configurations from one location.
Step 7: Test Configuration and Restart Nginx
Check for syntax errors in your Nginx configuration:
sudo nginx -t
If the test passes, reload Nginx to apply the changes:
sudo systemctl restart nginx
Note: On most modern systems, use systemctl
instead of the older service
command.
Step 8: Create Website Directory and Index File
Create the document root directory and add a simple index.html
file:
sudo mkdir -p /var/www/yourdomain.com
Open the file for editing:
sudo nano /var/www/yourdomain.com/index.html
Paste the following HTML code:
Step 9: Test Your Website
Open a web browser and navigate to:
http://yourdomain.com
You should see a blue "Hola" message centered on the page.
See Also
- Official Nginx Documentation
- Configure iptables on Linux - Secure your server by filtering unnecessary traffic.
Published on Aug 19, 2025