Saturday, November 22, 2025

Web Server-4.Nginx:Enable Userdir

 

Nginx : Enable Userdir2022/03/17

 
Enable Userdir for common users to open their site in the home directories.
[1]Configure Nginx. Add settings into the [server] section of a site definition you'd like to set.
[root@www ~]# 
vi /etc/nginx/conf.d/ssl.conf
# add into the [server] section

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

[root@www ~]# 
systemctl reload nginx

[2]If SELinux is enabled, change boolean setting.
[root@www ~]# 
setsebool -P httpd_enable_homedirs on

[3]Create a test page as a common user to verify it works normally.
[cent@www ~]$ 
chmod 711 /home/cent

[cent@www ~]$ 
mkdir ~/public_html

[cent@www ~]$ 
chmod 755 ~/public_html

[cent@www ~]$ 
vi ~/public_html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx UserDir Test Page
</div>
</body>
</html>


No comments:

Post a Comment