🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Web & Software Development › Deployment: Servers, CI/CD, and Cloud Publishing › Lesson 4
TEC-WEB46-07 · Lesson 4 · 14 clock hours · lab

Web Server Installation and Virtual Hosts

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.

⚠ Pending professional review

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.

What Is a Web Server?

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.

Safety and Access Considerations

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.

Installing Nginx with apt

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.

Understanding Server Blocks (Virtual Hosts)

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.

Creating a Server Block

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.

Uploading Files with scp

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.

Troubleshooting Checklist

Lab Log

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.

Key terms9

NginxAn open-source web server and reverse proxy known for high performance with static content; uses server blocks to define site configurations.
server blockNginx's configuration unit that defines how the server handles requests for a specific IP address or domain name, equivalent to Apache's virtual host.
systemctlThe command-line tool used to manage systemd services on Linux, including starting, stopping, enabling, disabling, and checking the status of services such as Nginx.
aptThe Advanced Package Tool used on Debian-based Linux distributions (such as Ubuntu) to install, update, and remove software packages from configured repositories.
scpSecure Copy Protocol; a command-line tool that transfers files between hosts over an encrypted SSH connection.
document rootThe directory on the server's filesystem that Nginx maps to the root URL of a site; files placed here are served to web clients.
symlink (symbolic link)A filesystem pointer that references another file or directory by path; used in Nginx's sites-available/sites-enabled pattern to activate or deactivate site configurations without deleting them.
port 80The well-known TCP port assigned to unencrypted HTTP traffic; a web server must listen on this port to respond to standard browser requests that do not specify a port.
nginx -tAn Nginx command that tests the current configuration files for syntax errors and reports whether the configuration is valid, without actually restarting the service.
In class: Install Nginx using apt, enable and start the service with systemctl, and verify it is running using systemctl status nginx. · Create an Nginx server block configuration file in /etc/nginx/sites-available/ pointing to a document root directory, then symlink it to sites-enabled and reload Nginx. · Upload a static index.html to the document root using scp and confirm the page loads in a browser by navigating to the server's IP address.
Materials: Student VPS, Nginx official documentation, scp or rsync, browser, lab log
Check: Instructor loads the student's IP in a browser and confirms the correct static page renders; Nginx config passes nginx -t without errors. Both required.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

CompTIA Linux+ – Managing Software
1. Which command installs Nginx on an Ubuntu VPS and automatically confirms all prompts?
CompTIA Linux+ – Managing Services
2. After installing Nginx, a student wants it to start automatically every time the server reboots. Which command accomplishes this?
CompTIA Linux+ – Configuring Network Services
3. A student creates an Nginx server block in /etc/nginx/sites-available/mysite but the new site does not load. The most likely missing step is:
CompTIA Linux+ – Configuring Network Services
4. Which command should a student run to check for Nginx configuration syntax errors before reloading the service?
CompTIA Linux+ – Securing Files and Data
5. A student uploads index.html to the VPS using the command: scp index.html deploy@203.0.113.5:/var/www/mysite/html/. Which statement about this transfer is correct?
CompTIA Linux+ – Troubleshooting
6. After reloading Nginx, a student navigates to the server's IP address in a browser and still sees the default Nginx welcome page instead of their index.html. Which diagnostic step is MOST directly relevant?
CompTIA ITF+ – Security Concepts
7. Which principle is applied when a student uses sudo only for specific commands during the Nginx lab instead of switching to the root user for the entire session?
CompTIA Linux+ – Configuring Network Services
8. In an Nginx server block, what is the purpose of the try_files $uri $uri/ =404; directive?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.