修改#vim /etc/httpd/conf.d/userdir.conf
修改内容 17行 UserDir disabled 前面加#
24行 UserDir public_html
用户目录 文件夹
重启服务 systemctl restart httpd
在用户目录新建 public_html 文件夹 并写入 index.html 文件
尝试访问 结果 不能访问
通过 临时关闭 selinux setenforce 0 结果 可以访问
开启 selinux sentenforce 1 结果 不能访问
结论 selinux 域 问题 确定
selinux 域 相关 off 禁用,on 允许
getsebool -a | grep http #查看selinux规则
httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> off
named_tcp_bind_http_port --> off
prosody_bind_http_port --> off
setsebool -P httpd_enable_homedirs=on 开启 httpd 用户目录访问
这个命令 不需要 restorecon
尝试访问 》可以
访问 网站需要 输入账号密码
#htpasswd -c /etc/httpd/passwd uhttp #uhttp是用户名
输入两次密码
修改文件配置
[root@linuxprobe ~]# vim /etc/httpd/conf.d/userdir.conf
27 #
28 # Control access to UserDir directories. The following is an example
29 # for a site where these directories are restricted to read-only.
30 #
31 <Directory “/home/*/public_html”>
32 AllowOverride all
# 密码验证文件的位置
33 authuserfile “/etc/httpd/passwd”
#提示信心
34 authname “My privately website”
35 authtype basic
#需要的用户名
36 require user uhttp
37
[root@linuxprobe ~]# systemctl restart httpd
尝试访问 ,出现 提示框 输入账号密码