Objective. Students install Nginx on their VPS, configure a server block (virtual host) for a test domain, and serve a static HTML page confirming the server responds on port 80.
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
A web server is software that listens for incoming HTTP requests on a network port and responds with files — HTML pages, images, stylesheets, scripts — or passes the request to an application back-end. Nginx (pronounced "engine-x") is a high-performance, open-source web server widely used in production environments. It handles static files efficiently and is a common choice for hosting websites on Linux virtual private servers (VPS).
In this lab you will install Nginx on a Linux VPS, configure it to serve a test site using a server block (Nginx's term for a virtual host), and confirm the site responds on port 80 — the default port for unencrypted HTTP traffic.
Before you begin, two operational safety points apply:
1. Principle of Least Privilege. Use `sudo` only for commands that require elevated permissions (package installation, service control, writing to `/etc/nginx/`). Do not work as the root user for your entire session.
2. Firewall awareness. Opening port 80 to the internet is intentional here, but always know which ports you are exposing. On a production server you would also configure HTTPS (port 443) and restrict other ports. For this lab, confirm your VPS firewall (such as `ufw`) allows port 80 before testing.
Debian-based distributions (including Ubuntu, which most student VPS instances run) use the apt package manager. Installing Nginx is a two-step process: update the local package index, then install.
```bash
sudo apt update
sudo apt install nginx -y
```
After installation, enable the service so it starts automatically on reboot, then start it immediately:
```bash
sudo systemctl enable nginx
sudo systemctl start nginx
```
Verify the service is running:
```bash
sudo systemctl status nginx
```
Look for `Active: active (running)` in the output. If you see a failure, check `/var/log/nginx/error.log` for details.
Nginx uses server blocks to define how it handles requests for different domains or IP addresses — the equivalent of Apache's VirtualHost directive. Nginx reads configuration from `/etc/nginx/nginx.conf`, which in turn includes all files found in `/etc/nginx/sites-enabled/`.
The standard workflow is:
1. Write a configuration file in `/etc/nginx/sites-available/` (a holding area).
2. Create a symbolic link from `sites-enabled/` to that file (this activates it).
3. Test the configuration with `nginx -t`.
4. Reload Nginx to apply the changes.
This two-directory pattern lets you disable a site by removing the symlink without deleting your configuration.
First, create a document root directory where your site's files will live:
```bash
sudo mkdir -p /var/www/mysite/html
sudo chown -R $USER:$USER /var/www/mysite/html
```
Next, create the server block configuration file:
```bash
sudo nano /etc/nginx/sites-available/mysite
```
Paste the following minimal configuration:
```nginx
server {
listen 80;
server_name YOUR_SERVER_IP;
root /var/www/mysite/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
```
Replace `YOUR_SERVER_IP` with your VPS's actual IP address. For a real domain name you would replace it with the fully qualified domain name (e.g., `example.com www.example.com`).
Now create the symlink and reload:
```bash
sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
```
The `nginx -t` command tests the configuration for syntax errors without restarting the server. Always run this before reloading. A misconfigured reload on a live server can take a site offline.
scp (Secure Copy Protocol) copies files over SSH. From your local machine, upload your `index.html` to the document root:
```bash
scp index.html user@YOUR_SERVER_IP:/var/www/mysite/html/
```
Replace `user` with your VPS username and `YOUR_SERVER_IP` with the actual address. Because scp uses SSH, the transfer is encrypted in transit — always prefer scp or rsync over unencrypted FTP.
After uploading, open a browser and navigate to `http://YOUR_SERVER_IP`. Your HTML page should appear. If you see the default Nginx welcome page instead, confirm that the symlink exists in `sites-enabled/` and that you reloaded Nginx after creating it.
Record every command you run, its output, and any errors you encountered and resolved. Your instructor will review your log alongside the live browser test. Accurate logs are a professional habit and an important part of this credential portfolio.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.