Enable Userdir in Nginx to allow users to host their own sites in home directories.
Add Userdir settings to the Nginx configuration file for the desired site.
Edit the site configuration file (e.g., ssl.conf for an SSL-enabled site):
[root@www ~]# vi /etc/nginx/conf.d/ssl.conf
# Add the following inside the server block:
server {
.....
.....
location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/public_html$2;
index index.html index.htm;
}
}
[root@www ~]# systemctl reload nginx
If SELinux is enabled, modify the SELinux boolean to permit web server access to home directories.
[root@www ~]# setsebool -P httpd_enable_homedirs on
Create a test page in the user's public_html directory to verify the configuration.
Execute the following commands as a common user (e.g., cent):
[cent@www ~]$ chmod 711 /home/cent
[cent@www ~]$ mkdir ~/public_html
[cent@www ~]$ chmod 755 ~/public_html
[cent@www ~]$ vi ~/public_html/index.html
# Add the following HTML content:
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx UserDir Test Page
</div>
</body>
</html>
After completing these steps, you should be able to access the user's website by navigating to http://www.yourdomain.com/~cent.