Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

Serve Per-User Web Pages with Nginx on Ubuntu 24.04

Configure Nginx on Ubuntu 24.04 to serve per-user URLs from dedicated home-directory web folders using a location rule and alias.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To serve URLs such as https://example.test/~alice/ from a user’s home directory on Ubuntu 24.04, add a location rule to the active Nginx server block and map each request to a dedicated directory such as /home/alice/public_html. Nginx does not include Apache’s mod_userdir module or UserDir directive; this behavior is configured with Nginx’s own location and filesystem rules.

What Nginx user-style URLs do

A request for /~alice/example.html can be mapped to /home/alice/public_html/example.html. The public_html folder is a convention you choose, not a directory Nginx requires. The important part is making the URL mapping match the directory layout you intend to publish.

As an Amazon Associate I earn from qualifying purchases.

Apache’s mod_userdir instructions configure Apache, not Nginx. For Nginx, use an appropriate location in the server block handling the site. See the Nginx core module documentation and Apache’s description of mod_userdir.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install Nginx and find the active site configuration

For a standard Ubuntu package installation, Ubuntu’s documented package workflow is:

sudo apt update && sudo apt install nginx
sudo systemctl status nginx

Ubuntu’s packaged configuration commonly uses /etc/nginx/sites-available and /etc/nginx/sites-enabled. Add the rule to the server block that actually handles the hostname; editing a different or inactive server block will not affect the request. Ubuntu documents the package and site configuration workflow in its Nginx installation guide and Nginx configuration guide. If Nginx was installed from source or another package source, its configuration path may differ; check the installation’s effective configuration path rather than assuming Ubuntu’s packaged layout.

Choose a dedicated public directory

A straightforward layout is /home/USERNAME/public_html, but you can choose another dedicated directory and adjust the mapping accordingly. Avoid mapping a user URL to the whole home directory when only a web folder should be public. Apache documents public_html as a per-user web-directory convention; for this Nginx setup, it is simply the administrator-selected path.

Create the directory and place only intended public files in it. For example, a request for /~alice/example.html should correspond to a real file at /home/alice/public_html/example.html.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add the Nginx location rule

Inside the relevant server { ... } block, add a rule like this:

location ~ ^/~(?<user>[a-zA-Z0-9_-]+)(?<path>/.*)?$ {
    alias /home/$user/public_html$path;
}

The regular expression captures the username and the remainder of the URL path. Nginx’s alias directive then maps the request to a filesystem path: /~alice/example.html resolves to /home/alice/public_html/example.html. In a regex location, Nginx documents using captures in the alias path so the complete target filename is explicit. Adapt the accepted username characters and directory path to your host’s actual policy. See the Nginx documentation for alias and location matching.

This pattern allows any matching username to be requested; it does not itself confirm that the corresponding account exists or decide which users are authorized to publish pages. If only selected users should have URLs, define a narrower policy in the Nginx configuration and ensure the filesystem layout and permissions enforce the same intent.

Set filesystem access without exposing private files

The Nginx worker process must be able to traverse the parent directories and read the files it serves. The required ownership and permissions depend on the worker’s user and group on your installation, so inspect those values and the permissions of each directory in the path before changing them. Do not use broad world-writable permissions as a shortcut. Keep private files outside the published directory.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Symlinks are another potential route to content outside the intended folder. Nginx documents the disable_symlinks directive, which defaults to off; stricter symlink handling can add processing overhead and has operational requirements. Consider whether a stricter policy is appropriate if users who can write within published directories may create symlinks. Directory listing is a separate choice: a directory URL without an index file may not display a listing unless listing is explicitly configured.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the configuration, reload, and verify a file

  1. Save the rule in the active server block, and confirm that its alias path matches the published directory.
  2. Check the configuration syntax: run sudo nginx -t. If Nginx reports an error, use the message and configuration include path to locate the problem.
  3. Reload Nginx: run sudo systemctl reload nginx after the syntax check succeeds.
  4. Request a known file: visit a URL such as https://example.test/~alice/example.html and confirm that it returns the intended file. Check the Nginx error log if the request fails.

Ubuntu documents enabling a site through its packaged configuration layout and reloading Nginx after changes in its Nginx configuration guide. A successful syntax check confirms the configuration parses; the URL request verifies that the host, location, filesystem path, and permissions work together.

Troubleshoot common failures

404 Not Found

  • Check that the requested file exists under the alias target, including the captured URL path.
  • Confirm the username and path captures match the directory structure you created.
  • Verify that the request reaches the server block containing this rule. Nginx’s server and location matching behavior is described in its core module documentation.

403 Forbidden

  • Check that the Nginx worker can traverse every parent directory and read the file.
  • If the URL points to a directory, confirm that an index file exists or decide whether directory listing should be configured.
  • Inspect the error log for the specific access failure before changing permissions.

Unexpected files are served

  • Review the alias target and ensure it points only to the intended public directory, not the user’s entire home directory.
  • Check the accepted username pattern and the permissions on published directories.
  • Review symlink handling if users can create links inside those directories.

Nginx rejects the rule

Run sudo nginx -t and read the reported error and file path. Check that the rule is inside a valid server block, that the named captures and alias path are spelled correctly, and that you edited a file included by the running installation. Ubuntu’s packaged paths may not apply to custom installations.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.