Debian 13 Tutorial / Configure Nginx Sites and Diagnose 403, 404 and File Permissions
On Debian 13, Nginx sites can store configurations in sites-available and be activated via symbolic links in sites-enabled. After checking the configuration, apply it with reload, and separately verify the port, Host value, file permissions, and actual HTTP responses. This tutorial adds a static site on 127.0.0.1:8080 while preserving the default site and compares the causes of 200, 403, and 404 responses.
Check the Static-site Lab’s Scope and Existing Listeners
Nginx is a web server that receives HTTP requests and serves files or passes the requests to other applications. Here, we will only configure a static site serving HTML files directly. You need a Debian 13 regular user with sudo privileges and curl, and all HTTP checks should be executed inside the Debian VM. The example listens only on guest loopback. Access from a host PC would require a separate plan for the listening address and forwarding; this lab keeps every request inside the VM.
During package installation, the default site may start. On an actual production server, first check for conflicts with existing web servers on ports 80 and 443 and establish maintenance procedures. Check that 127.0.0.1:8080 is unused as well. If another service occupies a needed address and port, stop this setup and identify the conflict instead of stopping that service.
ss -ltn
dpkg-query -W nginx nginx-common 2>/dev/null
apt-cache policy nginx
dpkg-query on uninstalled packages may return a non-zero status. That alone is not a system error. On the practice VM, Nginx was not installed and only SSH on port 22 was open. It was installed from the Debian repository as follows.
sudo apt update
sudo apt install nginx curl
nginx -v
systemctl is-active nginx
systemctl is-enabled nginx
sudo nginx -t
The nginx and nginx-common installed on this VM were version 1.26.3-3+deb13u10, and the service was active and enabled. Package revision numbers may vary depending on the deployment timing and security updates. If the service does not start, check the actual cause such as binding failure with systemctl status nginx --no-pager and sudo journalctl -u nginx -n 50 --no-pager.
Inspect Debian’s Include Paths and Back Up the Originals
The sites-available directory is where configuration files are stored, and not all files inside it are applied automatically. In the practice package, /etc/nginx/nginx.conf included /etc/nginx/conf.d/*.conf and /etc/nginx/sites-enabled/* within the http context. Proceed after checking this rule directly.
grep -nE 'user |include .*(conf.d|sites-enabled)' /etc/nginx/nginx.conf
ls -l /etc/nginx/sites-enabled
sudo nginx -T | less
nginx -T prints out all included configurations along with a check. Since authentication information or internal addresses may be included, the output is not published as-is. In less, exit with q. On this VM, the worker user was www-data, and the default site link was maintained.
The following is a preparation block to check that the practice path does not exist and to preserve the original. Execute in the same Bash terminal. If the path already exists, stop without deleting or overwriting. Backups of operating configurations prepared by the reader should also include all related include files and certificates.
set -euo pipefail
for p in /srv/lf-web25 /etc/nginx/sites-available/lf-web25 /etc/nginx/sites-enabled/lf-web25 /var/backups/lf-debian13-25; do
if test -e "$p" || test -L "$p"; then
echo "Path already exists: $p" >&2
exit 1
fi
done
sudo install -d -m 700 /var/backups/lf-debian13-25
sudo cp -a /etc/nginx/nginx.conf /etc/nginx/sites-available/default /var/backups/lf-debian13-25/
sudo sha256sum /etc/nginx/nginx.conf /etc/nginx/sites-available/default | sudo tee /var/backups/lf-debian13-25/original.sha256
Create Static Files and the Complete Virtual-host Configuration
Practice site files are placed in /srv/lf-web25/public. The administrator owns the files, and the Nginx worker can only read them. Directories need execute permission to traverse the path, and files need read permission. This example applies only to public static files, and passwords or private materials are not placed in this path.
sudo install -d -m 755 /srv/lf-web25/public /srv/lf-web25/public/empty
printf '%s
' '<!doctype html><html lang="en"><meta charset="utf-8"><title>Lab 25</title><h1>LF WEB 25</h1></html>' | sudo tee /srv/lf-web25/public/index.html
sudo chmod 644 /srv/lf-web25/public/index.html
Write the entire next block into the configuration file. The quoted heredoc terminator CONF preserves $uri as an Nginx variable, not as a shell variable. The shell wrapper is a Bash block; the content between the CONF markers is the complete Nginx configuration.
sudo tee /etc/nginx/sites-available/lf-web25 > /dev/null <<'CONF'
server {
listen 127.0.0.1:8080 default_server;
server_name _;
return 404;
}
server {
listen 127.0.0.1:8080;
server_name lab25.test;
root /srv/lf-web25/public;
index index.html;
access_log /var/log/nginx/lf-web25-access.log;
error_log /var/log/nginx/lf-web25-error.log;
location / {
try_files $uri $uri/ =404;
}
}
CONF
| Settings | Role of this practice |
|---|---|
| listen 127.0.0.1:8080 | It only accepts connections from the VM's own loopback. It cannot be directly accessed from the internet. |
| default_server | Specifies the default server for requests with mismatched names at that address and port. |
| server_name lab25.test | Sends host-matching requests to the actual site. It does not create DNS records. |
| root and index | Sets the file path to find the request URI and the default file for the directory. |
| try_files $uri $uri/ =404 | Checks the file or directory and returns 404 if not found. |
The server_name _ itself is not a special wildcard that catches all names. Here, default_server determines the default choice. If you duplicate this on the same address and port, an error may occur, so check the existing settings. Nginx's request handling documentation explains the order of first selecting the address and port, then determining the Host name and default server.
Connect and check the configuration file, then apply it. Continue in the dedicated Bash session. The following && chain runs reload only when nginx -t succeeds; a failed check must be corrected before proceeding.
sudo ln -s /etc/nginx/sites-available/lf-web25 /etc/nginx/sites-enabled/lf-web25
sudo nginx -t && sudo systemctl reload nginx
systemctl is-active nginx
ss -ltn | grep '127.0.0.1:8080'
Reload makes it read the configuration again, but the act of saving the configuration file itself is not applied to the running process. Even if it passes the check, it does not guarantee the worker's actual file reading permissions or the desired Host response, so HTTP verification continues. The scope of the nginx -t and -T options can be checked in Debian nginx command documentation.
Compare Host Selection, HTTP Results and DNS
The following command uses --noproxy to exclude the effects of proxy environment variables. The first request is to the actual site, the second is to the default server with a mismatched name, the third is a nonexistent file, and the fourth is a directory without an index.
curl --noproxy '*' -i -H 'Host: lab25.test' http://127.0.0.1:8080/
curl --noproxy '*' -i -H 'Host: other.test' http://127.0.0.1:8080/
curl --noproxy '*' -i -H 'Host: lab25.test' http://127.0.0.1:8080/missing
curl --noproxy '*' -i -H 'Host: lab25.test' http://127.0.0.1:8080/empty/
| Request | Verified Result | Interpretation |
|---|---|---|
| lab25.test / | 200, LF WEB 25 | Selected the desired site and static files. |
| other.test / | 404 | This is the explicit return value of the default server. |
| lab25.test /missing | 404 | Could not find the target file on the matching site. |
| lab25.test /empty/ | 403 | There is a directory, but no index, and directory listing is not allowed. |
By default, curl does not treat receiving HTTP 404 as a process failure. For automated checks, use -f to return failure on HTTP error responses, or print the status with -w and compare it explicitly. Printing a status with -w alone does not make an HTTP error produce a failing curl exit status. To write the site name in the URL but request it without changing the public DNS, use the following command. --resolve provides name, port, and address mapping only for this curl request.
curl --noproxy '*' -fsS --resolve lab25.test:8080:127.0.0.1 http://lab25.test:8080/
Even if the command succeeds, lab25.test is not registered in the internet DNS. To make an external service public, you need an actual domain, the path to the server, an appropriate listen address, firewall, and HTTPS separately. Following this exercise does not require opening port 8080 externally.
Match File-permission Failures to Error Logs
Even if you get the same 403, the cause may differ. Below is a comparison where we changed only one root-owned file created in this exercise to 600, removing the worker's read permission, and then made a request. Do not apply this to operational files. Check the HTTP status and immediately revert it to 644.
sudo chmod 600 /srv/lf-web25/public/index.html
curl --noproxy '*' -sS -o /dev/null -w '%{http_code}
' -H 'Host: lab25.test' http://127.0.0.1:8080/
namei -l /srv/lf-web25/public/index.html
sudo tail -n 10 /var/log/nginx/lf-web25-error.log
sudo chmod 644 /srv/lf-web25/public/index.html
curl --noproxy '*' -fsS -H 'Host: lab25.test' http://127.0.0.1:8080/
The actual result was 403 with Permission denied when set to 600, and 200 after restoration. The previous /empty/ request was logged as directory index is forbidden, so it was distinguishable. namei shows permissions up to the intermediate directories. If you do not have directory-traversal permission on a parent directory, the final file cannot be read even if it is 644.
Do not solve it with chmod -R 777. Check the path, owner, worker account, access control lists (ACLs), and AppArmor denial logs if necessary, and only grant the permissions needed. Even if Nginx configuration check succeeds as root, it is not the same as the www-data worker being able to read. The access log is used to see requests and status, and the error log is used to narrow down the reason for denial.
Recover the Site Configuration and Clean Up the Lab
Before changing the settings, make a separate copy of the known-good version of this site. During the verification process, while a configuration with unknown directives is rejected by nginx -t, the existing workers that have not been reloaded continued to return 200. Restore the failed file to the known-good version and check again. Readers should get into the habit of copying, checking, and applying the known-good version without creating errors in the production settings.
sudo cp -a /etc/nginx/sites-available/lf-web25 /var/backups/lf-debian13-25/good-site
sudo nginx -t && sudo systemctl reload nginx
curl --noproxy '*' -fsS -H 'Host: lab25.test' http://127.0.0.1:8080/
To restore this lab file, compare it with sudo diff -u /var/backups/lf-debian13-25/good-site /etc/nginx/sites-available/lf-web25. If the saved file is the intended version, restore it with sudo cp -a /var/backups/lf-debian13-25/good-site /etc/nginx/sites-available/lf-web25. Run the guarded nginx -t/reload command above and repeat the Host-specific HTTP request. Preserve any newer intended edits before copying.
If there is a problem with the changed site, compare the just-saved known-good version with the current file and restore only the file for that site. Do not recklessly overwrite the common settings. The worker replacement behavior on reload and handling in case of failure can be confirmed in Nginx configuration reload guide .
To end the practice, first remove the link and shut down the dedicated server on 8080 with check and reload. Do not stop the default site or the entire Nginx service. If you want to keep logs before performing the steps below, copy the two dedicated logs to the backup folder.
sudo cp -a /var/log/nginx/lf-web25-access.log /var/log/nginx/lf-web25-error.log /var/backups/lf-debian13-25/
sudo rm -- /etc/nginx/sites-enabled/lf-web25
sudo nginx -t && sudo systemctl reload nginx
ss -ltn
sudo sha256sum -c /var/backups/lf-debian13-25/original.sha256
Right after the reload, allow some time for existing workers to finish requests, then check again. After confirming that the 127.0.0.1:8080 listener is gone and the original hash is OK, clean up only the dedicated files. In the production environment, also check that the workers in use are no longer accessing the dedicated logs.
sudo rm -- /etc/nginx/sites-available/lf-web25 /srv/lf-web25/public/index.html
sudo rmdir /srv/lf-web25/public/empty /srv/lf-web25/public /srv/lf-web25
sudo rm -- /var/log/nginx/lf-web25-access.log /var/log/nginx/lf-web25-error.log
systemctl is-active nginx
In the final verification, the dedicated listener and files were removed, the hashes of nginx.conf and the default site were maintained, and Nginx itself was active. The installed packages were retained. The removal of packages will be decided separately after checking their use with other sites and future usage.




