前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何在RHEL/CentOS上启用Apache Userdir模块

如何在RHEL/CentOS上启用Apache Userdir模块

作者头像
星哥玩云
发布2022-07-27 20:56:27
4060
发布2022-07-27 20:56:27
举报
文章被收录于专栏:开源部署

User Directory或Userdir是一个Apache模块,它允许使用http://example.com/~user/语法通过Apache Web服务器检索特定于用户的目录。

例如,当启用mod_userdir模块时,系统上的用户帐户将能够通过Apache Web服务器访问其主目录中的内容。

在本文中,我们将向您展示如何使用Apache Web服务器在RHEL,CentOS和Fedora服务器上启用Apache userdirs(mod_userdir)。

本教程假设您已经在Linux发行版上安装了Apache Web服务器。 如果还没有,可以使用以下步骤安装它...

第1步:安装Apache HTTP Server

要安装Apache Web服务器,请在Linux发行版上使用以下命令。

[linuxidc@localhost www.linuxidc.com]$ sudo yum install httpd          [在 CentOS/RHEL 上] [linuxidc@localhost www.linuxidc.com]$ sudo dnf install httpd          [在 Fedora 上]

如何在RHEL/CentOS上启用Apache Userdir模块
如何在RHEL/CentOS上启用Apache Userdir模块

在CentOS 7上安装Apache

第2步:启用Apache Userdirs

现在,您需要配置Apache Web服务器以在配置文件/etc/apache2/mods-available/userdir.conf中使用此模块,该文件已配置了最佳选项。

# vi /etc/httpd/conf.d/userdir.conf

然后验证内容如下所示。

# directory if a ~user request is received. # # The path to the end user account 'public_html' directory must be # accessible to the webserver userid.  This usually means that ~userid # must have permissions of 711, ~userid/public_html must have permissions # of 755, and documents contained therein must be world-readable. # Otherwise, the client will only receive a "403 Forbidden" message. # <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 linuxidc

    #     # 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>

# # Control access to UserDir directories.  The following is an example # for a site where these directories are restricted to read-only. # <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>

如何在RHEL/CentOS上启用Apache Userdir模块
如何在RHEL/CentOS上启用Apache Userdir模块

要允许少数用户访问UserDir目录,但不允许其他人访问,请在配置文件中使用以下设置。

UserDir disabled UserDir enabled testuser1 testuser2 testuser3

要允许所有用户访问UserDir目录,但对少数用户禁用此功能,请在配置文件中使用以下设置。

UserDir enabled UserDir disabled testuser4 testuser5 testuser6

根据需要进行配置设置后,需要重新启动Apache Web服务器以应用最近的更改。

# systemctl restart httpd.service  [在 SystemD 上] # service httpd restart            [在 SysVInit 上]

第3步:创建用户目录

现在,您需要在user/users主目录中创建一个public_html 目录/目录。 例如,这里我在linuxidc的用户主目录下创建一个public_html目录。

# mkdir /home/linuxidc/public_html

接下来,在用户home和public_html目录上应用正确的权限。

# chmod 711 /home/linuxidc # chown linuxidc:linuxidc /home/linuxidc/public_html # chmod 755 /home/linuxidc/public_html

另外,为Apache homedir(httpd_enable_homedirs)设置正确的SELinux context。

# setsebool -P httpd_enable_homedirs true # chcon -R -t httpd_sys_content_t /home/linuxidc/public_html

第4步:测试启用Apache Userdir

最后,通过将浏览器指向服务器主机名或IP地址,然后是用户名来验证Userdir。

http://www.linuxidc.com/~linuxidc/ 或 http://IP地址/~linuxidc

如何在RHEL/CentOS上启用Apache Userdir模块
如何在RHEL/CentOS上启用Apache Userdir模块
如何在RHEL/CentOS上启用Apache Userdir模块
如何在RHEL/CentOS上启用Apache Userdir模块

如果需要,还可以通过创建以下文件来测试HTML页面和PHP信息。

使用以下内容创建/home/linuxidc/public_html/linuxidc.com.html文件。

<html>   <head>     <title>linuxidc.com is Best Site for Linux</title>   </head>   <body>     <h1>linuxidc.com is Best Site for Linux</h1>   </body> </html>

如下图:

如何在RHEL/CentOS上启用Apache Userdir模块
如何在RHEL/CentOS上启用Apache Userdir模块

使用以下内容创建/home/linuxidc/public_html/linuxidc.com.php文件。

<?php   phpinfo(); ?>

OK,在本文中,我们解释了如何启用Userdir模块来允许用户共享来自其主目录的内容。如果您对本文有任何疑问,请在下面的评论部分提出。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档