Skip to content
Follow
Ubuntu Linux

How to Enable Nginx Userdir on Ubuntu 24.04 Easily

Richard
Written by
Richard
Feb 19, 2025 Updated Oct 13, 2026 5 min read
Enable Nginx Userdir on Ubuntu 24.04
Enable Nginx Userdir on Ubuntu 24.04

Nginx userdir on Ubuntu 24.04 lets you host personal websites from your home folder, using a folder named public_html. Each person on the system gets their own web space at http://example.com/~username, without needing control of the main server configuration.

Advertisement
⚡ Quick Answer

Open /etc/nginx/sites-available/default with sudo nano, add a location ~ ^/~(.+?)(/.*)?$ block inside the server block that aliases /home/$1/public_html$2, then run sudo systemctl restart nginx. Create ~/public_html with chmod 755, because Ubuntu 24.04 makes home folders private by default. Each user then gets a page at http://your_ip_address/~username/.

Advertisement

This is handy on shared machines or for local testing, when you want users to publish pages without touching the main web root. The steps below assume Nginx is already installed and running, and that you can use sudo. Only the configuration steps need administrator rights. The folder and page steps are done as the user who will own the site.

  1. Open the default Nginx site configuration file in a text editor with root rights: sudo nano /etc/nginx/sites-available/default. The file opens in your terminal editor.
  2. Find the server block, then add the following lines inside it. Put them inside the block’s curly braces, not after the closing brace:
    💻Code
    location ~ ^/~(.+?)(/.*)?$ { alias /home/$1/public_html$2; index index.html index.htm; autoindex on; }
  3. Save the file and close the editor. If you use nano, press Ctrl+O, then Enter, then Ctrl+X.
  4. Restart Nginx to apply the change: sudo systemctl restart nginx. If Nginx fails to start, you most likely made a typo or put the lines outside the block. Reopen the file and check it.
  5. Log in as the user who will own the site. Create a folder named public_html in that user’s home directory: mkdir ~/public_html
  6. Set the correct permissions on the folder: chmod 755 ~/public_html. Nginx runs as its own account, not as you, so it must be able to read the files. It also needs permission to pass through your home folder to reach them. Ubuntu 24.04 makes new home folders private by default, so a 403 Forbidden error later usually means the home folder or the public_html folder blocks other users.
  7. Create a simple index.html file inside the new folder: nano ~/public_html/index.html. The editor opens with an empty file.
  8. Add some basic HTML content, like:
    💻Code
    <html><title>My Userdir Page</title><body><h1>Hello from my userdir!</h1></body></html>
  9. Save and close the index.html file.
  10. Open your browser and go to http://your_ip_address/~your_username/. Replace the username and server address with your own. You should see the page you just wrote. If you see 404 Not Found, check the file name and folder location. If you see 403 Forbidden, recheck the permissions from step 6.

Enable Userdir

In short, enabling Nginx userdir on Ubuntu 24.04 means opening the main server configuration file and adding the lines that point to each user’s public_html folder. This tells Nginx where to find and serve files for every user account.

The change is small. You open the default Nginx site configuration and add a few specific lines inside the server block. After that, any user who creates a public_html folder with content in it gets a page at their own ~username address. You don’t need to edit the configuration again when you add more users.

🐧Bash / Shell
sudo nano /etc/nginx/sites-available/default

Open the file and add the highlighted lines inside the server block, as shown below.

Advertisement

💻Code
server {
listen 80 default_server;
listen [::]:80 default_server;
#
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;

location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/public_html$2;
index index.html index.htm;
autoindex on;
}


.........
........
💡Tip

Restart Nginx once the lines are in place so the change takes effect. A restart briefly interrupts active connections. That is fine on a test machine, but on a busy server you may prefer a reload instead.

🐧Bash / Shell
sudo systemctl restart nginx
📝Good to Know

There is nothing else to configure once the feature is enabled. To undo it, remove the lines you added, save the file and restart Nginx. The public_html folders and their files stay where they are.

Advertisement

Test Nginx Userdir

To test Nginx Userdir Ubuntu 24.04 and make sure your home folder website works, create a public_html directory with the correct folder permissions and add a test HTML file. Visiting the server URL in your browser confirms that the web server reads user directories properly.

Testing your Nginx Userdir setup on Ubuntu 24.04 confirms that your website hosted from a home folder is accessible. You'll create a 'public_html' folder, set its permissions correctly, and place a basic HTML file inside. This simple test verifies that Nginx can find and display your page, showing that Nginx Userdir is working as expected.

Advertisement

First, run the command below to create a 'public_html' document root in your home directory.

Advertisement

💻Code
mkdir ~/public_html

Update the permissions on the directory to ensure they are secure.

Advertisement

🐧Bash / Shell
chmod 711 $HOME
chmod 755 ~/public_html

Advertisement

Next, run the command below and add a basic HTML 'index.html' file.

💻Code
nano ~/public_html/index.html

Copy and paste the lines below into the file and save.

💻Code
<html>
<title>My basic HTML page</title>
<body>
<p style="width: 100%; font-weight: bold; font-size: 60px; text-align: center;">
UserDir is enabled!
</p>
</body>
</html>

Save the file and exit.

You can now view your personal web pages by opening your web browser and entering your IP address followed by your username and "userdir" in the address bar, for example: `http://your_ip_address/~your_username/userdir`.

💻Code
http://example.com/~richard/

Add the ~username after the server hostname or IP address.

Apache userdir feature enabled on a Linux server environment
Apache userdir feature enabled on a Linux server environment

That should do it~

Conclusion:

Enabling the Nginx Userdir feature on Ubuntu 24.04 provides users with a convenient way to host their personal web pages without requiring administrative access. Here are some key points to remember:

    • User-Friendly: Allows users to manage their web content from their home directory easily.

    • Configuration: Requires modification of the Nginx configuration file to include the necessary location block.

    • Permissions: It's essential to set appropriate permissions for the public_html directory to ensure security.

    • Testing: A simple HTML file can be created to verify that the Userdir feature is working correctly.

    • Access: Users can access their web pages through a simple URL format (http://yourserver/~username).

Nginx userdir lets you host personal websites by serving files from your home directory. This feature simplifies sharing your projects online after following the setup steps.

Does nginx run on Ubuntu?

Nginx is available in Ubuntu's default repositories. Install it using the apt packaging system. First, update the local package index to access the most recent package listings, then install nginx : sudo apt update.

Which user runs nginx?

As you can see in the first column, the initial nginx master process is started with the root user account.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

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