Ubuntu 26.04

Nginx : Enable Userdir2026/05/27

 

Enable Userdir for common users to open their site in the home directories.

[1] Configure Nginx. Add settings into [server] section of a site definition you'd like to set.
root@www:~#
vi /etc/nginx/sites-available/default
# add into [server] section

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

root@www:~#
systemctl reload nginx

[2] Create a test page with a common user to make sure it works normally.
ubuntu@www:~$
chmod 711 $HOME

ubuntu@www:~$
mkdir ~/public_html

ubuntu@www:~$
chmod 755 ~/public_html

ubuntu@www:~$
vi ~/public_html/index.html
<html>
<body>
<h1 style="width: 100%; font-size: 40px; text-align: center;">
Nginx UserDir Test Page
</h1>
</body>
</html>
Matched Content