UserDir 模组可以让服务器的帐号, 拥有自己的网页, 即在服务器的主机名称后面加上 “~username” 作为个人网页。以下是在 RHEL 及 CentOS 开启 UserDir 个人网页模组, 以及设定 SELinux 的方法..
在 CentOS 只要用 yum 安装了 Apache (httpd), 默认已经安装了 UserDir 模组, 只要在 httpd.conf 或 /etc/httpd/conf.d/ 下面建立设定档便可以启用。可以用以下指令确认是否有 UserDir 模组:
-
# grep userdir /etc/httpd/conf.modules.d/00-base.conf
LoadModule userdir_module modules/mod_userdir.so
如果看到如上面的输出, 即已经安装了 UserDir.
第一步是建立 UserDir 的设定档:
- # vi /etc/httpd/conf.d/userdir.conf
加入以下内容, 以下假设开启的使用者名称是 testuser:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<ifmodule mod_userdir.c=""> # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # UserDir enabled testuser # # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disabled" line above, and uncomment # the following line instead: # UserDir public_html </ifmodule> <directory home="" *="" public_html=""> ## Apache 2.4 users use following ## AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS ## Apache 2.2 users use following ## Options Indexes Includes FollowSymLinks AllowOverride All Allow from all Order deny,allow </directory> |
储存盘案后离开 vi.
如果需要开启个帐号的个人网页, 但其他帐号不开启, 用以下语法:
UserDir enabled testuser1 testuser2 testuser3
如果所有帐号开启个人网页, 但个别几个帐号不开启, 用以下语法:
To allow most users to have UserDir directories, but deny this to a few, use the following:
UserDir disabled testuser4 testuser5 testuser6
设定后重新启动 Apache:
- # systemctl restart httpd
建立使用者帐号的网页目录, 根据上面设定在 testuser 帐号家目录下的 public_html, 并设定正确权限:
-
# mkdir /home/testuser/public_html
# chmod 711 /home/testuser
# chown testuser:testuser /home/testuser/public_html
# chmod 755 /home/testuser/public_html
建立测试页面:
- # echo ‘userdir test’ >> /home/testuser/public_htmlindex.html
最后开启 SELinux 的 httpd_enable_homedirs 及设定 httpd_sys_content_t:
-
# setsebool -P httpd_enable_homedirs true
# chcon -R -t httpd_sys_content_t /home/testuser/public_html
现在可以在服务器的网址后面加上 “~testuser” 开启使用者帐号的网页目录, 例如:
http://localhost/~testuser/
这时如果设定正确, 便可以看到上面建立的测试页面 index.html, 输出 “userdir test”.