Skip to content
Follow
Ubuntu Linux

How to Enable Nginx Userdir on Ubuntu 24.04 Easily

Richard
Written by
Richard
Feb 19, 2025 Updated Jul 19, 2026 4 min read
Enable Nginx Userdir on Ubuntu 24.04
Enable Nginx Userdir on Ubuntu 24.04

Nginx Userdir on Ubuntu 24.04 lets you serve websites directly from a user’s home folder, usually a folder named public_html.

⚡ Quick Answer

Configure Nginx by editing the default site file to add a location block for user directories. After saving the configuration, restart the Nginx service to apply the changes. Test by creating a `public_html` folder in your home directory and adding an `index.html` file.

This feature allows individuals to host their own web pages without needing full server control. It’s similar to how Apache handles user directories.

Enabling Nginx Userdir is handy for shared hosting or when you want to make it simple for people to put their websites online.

📋 Quick Steps
  1. Open the default Nginx site configuration file by running: sudo nano /etc/nginx/sites-available/default
  2. Add the following lines inside the server block to set up user directories:
    💻Code
    location ~ ^/~(.+?)(/.*)?$ { alias /home/$1/public_html$2; index index.html index.htm; autoindex on; }
  3. Save the file and close it.
  4. Restart Nginx to apply the changes with: sudo systemctl restart nginx
  5. Create a folder named public_html in your home directory: mkdir ~/public_html
  6. Set the correct permissions for this folder: chmod 755 ~/public_html
  7. Create a simple index.html file inside your new folder: nano ~/public_html/index.html
  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. You can now see your page by going to http://your_ip_address/~your_username/ in your browser.

Enable Userdir

Enabling Nginx Userdir on Ubuntu 24.04 lets you host websites directly from your home folder. You’ll modify the main Nginx configuration file to tell the server to look for web files inside each user’s ‘public_html’ directory. This involves opening the default Nginx site configuration and adding a few specific lines to make user directories work.

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

Then, edit the file and add the highlighted lines under the [server] block.

💻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;
}


.........
........

⚠️Warning
Restart Nginx once enabled to apply your changes.

🐧Bash / Shell
sudo systemctl restart nginx

There is nothing else to configure once the feature is enabled.

Test Nginx Userdir

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.

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

💻Code
mkdir ~/public_html

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

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

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.

What is the default user in nginx admin?

login nginx admin ui default user/password is admin / admin , password change is required after first login.

Was this guide helpful?

📬 Get new Windows tips in your inbox
One email when we publish something worth your time. No spam, unsubscribe anytime.
Tags: #Nginx #Ubuntu Linux
Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

2769 articles → Twitter

📚 Related Tutorials

How to Install Apache on Ubuntu Linux
Ubuntu Linux How to Install Apache on Ubuntu Linux
How to Install Nginx on Ubuntu Linux
Ubuntu Linux How to Install Nginx on Ubuntu Linux
How to Enable File Sharing Between Ubuntu and Windows 11
Windows How to Enable File Sharing Between Ubuntu and Windows 11
How to Install Drupal with Nginx and Cloudflare on Ubuntu
CMS How to Install Drupal with Nginx and Cloudflare on Ubuntu

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

Leave a Comment

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