[Ubuntu Server Setup] Part 4: Installing Nginx and Running Your First Website
![[Ubuntu Server Setup] Part 4: Installing Nginx and Running Your First Website](/uploads/editor/Ubuntu-서버-구축-4강-Nginx-설치와-첫-번째-웹사이트-운영하기-20260708-82493e.webp)
Finally, Let's Install a Web Server
Hello.
Last time, we covered common terminal commands, file management, and the Linux permission system in Ubuntu.
This session marks the beginning of setting up actual web services.
We'll install Nginx web server to operate your first homepage.
The moment you see a webpage appear when entering your server's IP address into a browser is often the most memorable part for those new to building servers.
It's simpler than it seems—just follow along step by step.
What Is Nginx?
Nginx (pronounced "engine-x") is a web server program that receives browser requests and delivers web pages.
In simple terms, it's the first program to handle requests when visitors access your website.
Today, many websites—from personal blogs to large enterprise services—use Nginx.
Nginx is widely adopted because of:
Exceptional speed
Low memory usage
High capacity for simultaneous connections
Reverse Proxy support
Easier HTTPS configuration
Compatibility with various services like PHP, Node.js, and Spring Boot
We'll continue using Nginx as the foundation for building your server in upcoming lessons.
System Update Before Installation
Before installing new software, it's good practice to update your package list.
Run this command first:
sudo apt update
Once the update completes, you're ready to install Nginx.
Installing Nginx
In Ubuntu, you can install Nginx with a single command:
sudo apt install nginx -y
After installation completes, the service usually starts automatically.
The process takes just a few seconds—no complex steps required.
Verifying Nginx Is Running
Once installed, check if the service is running:
sudo systemctl status nginx
If it's working correctly, you'll see:
active (running)
This confirms Nginx is running properly.
Accessing via Browser
Now for the key test.
In your browser, enter:
http://serverIP
For example, if your server IP is
192.168.0.20
you'd access it as:
http://192.168.0.20
If you see the
Welcome to nginx!
page, installation was successful.
The moment your server serves a webpage is often fascinating for beginners.
Finding Your Server IP Address
If you don't know your IP address:
hostname -I
or
ip addr
You'll see your server's internal IP address.
Nginx Service Control
Nginx runs as a service, so you can start or stop it when needed.
Start the service:
sudo systemctl start nginx
Stop the service:
sudo systemctl stop nginx
Restart:
sudo systemctl restart nginx
Reload configuration only:
sudo systemctl reload nginx
Check status:
sudo systemctl status nginx
You'll use these commands frequently moving forward.
Auto-start on Boot
In Ubuntu, you can set Nginx to start automatically after reboot:
sudo systemctl enable nginx
If auto-start isn't needed:
sudo systemctl disable nginx
Most production servers use automatic startup.
Default Website Location
Nginx serves files from the following directory by default:
/var/www/html
To check what's there, run:
cd /var/www/html
Then:
ls
You'll see the default file:
index.nginx-debian.html
This is the welcome page you see initially.
Create Your First HTML Page
Now create your own webpage.
You can either edit the existing file or create a new one. For example:
sudo nano /var/www/html/index.html
Create simple HTML like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Server</title>
</head>
<body>
<h1>Hello Ubuntu Server!</h1>
<p>First website here.</p>
</body>
</html>
After saving, refresh your browser to see your custom page.
Your server is now serving a real webpage.
Where Are the Configuration Files?
Nginx configuration files are mostly stored in:
/etc/nginx
The most important folders include:
/etc/nginx/nginx.conf
Overall configuration file.
/etc/nginx/sites-available
Where website configurations are stored.
/etc/nginx/sites-enabled
Where active sites are linked from.
You'll use these often when managing multiple websites later.
Checking Configuration Syntax
Before making changes, always check for syntax errors:
sudo nginx -t
If correct, you'll see:
syntax is ok
test is successful
Then apply the changes with:
sudo systemctl reload nginx
Check Your Firewall
If you can't access the site, your firewall might be blocking it.
In Ubuntu with UFW enabled:
sudo ufw allow 'Nginx Full'
This allows both HTTP and HTTPS traffic.
Firewall settings are covered in more detail later, but if you can't connect, this is the first thing to check.
Why Learn Nginx?
A web server isn't just for serving static HTML files.
All of these will be built around Nginx:
PHP
MySQL
HTTPS
Reverse Proxy
Managing multiple domains
In short, this lesson is the foundation for all future lessons.
What You Learned Today
This session covered installing Nginx on Ubuntu and operating your first website. We also explored service management, default web page location, and configuration structure.
In the next lesson, we'll connect Nginx with PHP to create dynamic websites beyond static HTML pages.
Key Takeaways
Nginx is a web server that handles browser requests.
In Ubuntu, you can install it easily with the apt command.
If you see the Welcome page in your browser after installation, everything's working correctly.
The default website directory is
/var/www/html.Configuration files are stored in
/etc/nginx.You can start, stop, and restart the service using
systemctl.Always check syntax with
nginx -tbefore applying changes.
Next Lesson Preview
Part 5: Installing PHP-FPM and Connecting to a PHP Website
In the next lesson, we'll connect Nginx with PHP-FPM to create dynamic websites that execute PHP code. This moves beyond simple static HTML pages into real web development environments.
FAQ
Is Nginx difficult to set up?
No, Nginx is straightforward to install on Ubuntu using a single command. The process takes just seconds with no complex steps.
Where does Nginx store website files by default?
Nginx serves files from /var/www/html by default in Ubuntu.
How do I check if Nginx is running correctly?
Run 'sudo systemctl status nginx'—if it shows 'active (running)', Nginx is working properly.
Korean Source
This article is an English localization of a Korean-language report from BlogScore. Original: [Ubuntu 서버 구축] 4강. Nginx 설치와 첫 번째 웹사이트 운영하기