通过更改SElinux状态可以判断出,当SElinux处于关闭状态时,网站内容访问正常。

[root@master1-192-168-117-18 ~]# setenforce 0

[root@master1-192-168-117-18 ~]# getenforce

Permissive

[root@master1-192-168-117-18 ~]# setenforce 1

[root@master1-192-168-117-18 ~]# getenforce 0

Enforcing

查看网站的主目录的SElinux安全上下文值:

[root@master1-192-168-117-18 ~]# ls -Zd /var/www/html/

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/

[root@master1-192-168-117-18 ~]# ls -Zd /home/wwwroot/

drwxr-xr-x. root root system_u:object_r:user_home_dir_t:s0 /home/wwwroot/

将新添加的主目录SElinux上下文值与系统默认主目录保持一致:

[root@master1-192-168-117-18 ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/*

注意,执行上述设置之后,还无法立即访问网站,还需要使用restorecon命令将设置好的SELinux安全上下文立即生效。在使用restorecon命令时,可以加上-Rv参数对指定的目录进行递归操作,以及显示SELinux安全上下文的修改过程。

[root@master1-192-168-117-18 ~]# restorecon -Rv /home/wwwroot/

restorecon reset /home/wwwroot context system_u:object_r:user_home_dir_t:s0->system_u:object_r:httpd_sys_content_t:s0

restorecon reset /home/wwwroot/index.html context system_u:object_r:user_home_t:s0->system_u:object_r:httpd_sys_content_t:s0

[root@master1-192-168-117-18 ~]# ls -Zd /home/wwwroot/

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /home/wwwroot/

[root@master1-192-168-117-18 ~]# ^C

个人用户主页功能

第1步:在httpd服务程序中,默认没有开启个人用户主页功能。为此,我们需要编辑下面的配置文件,然后在第17行的UserDir disabled参数前面加上井号(#),表示让httpd服务程序开启个人用户主页功能;同时再把第24行的UserDir public_html参数前面的井号(#)去掉(UserDir参数表示网站数据在用户家目录中的保存目录名称,即public_html目录)。最后,在修改完毕后记得保存。

[root@master1-192-168-117-18 ~]# vim /etc/httpd/conf.d/userdir.conf

1 #

2 # UserDir: The name of the directory that is appended onto a user's home

3 # directory if a ~user request is received.

4 #

5 # The path to the end user account 'public_html' directory must be

6 # accessible to the webserver userid. This usually means that ~userid

7 # must have permissions of 711, ~userid/public_html must have permissions

8 # of 755, and documents contained therein must be world-readable.

9 # Otherwise, the client will only receive a "403 Forbidden" message.

10 #

11

12 #

13 # UserDir is disabled by default since it can confirm the presence

14 # of a username on the system (depending on home directory

15 # permissions).

16 #

17 # UserDir disabled

18

19 #

20 # To enable requests to /~user/ to serve the user's public_html

21 # directory, remove the "UserDir disabled" line above, and uncomment

22 # the following line instead:

23 #

24 UserDir public_html

25

26

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

32 AllowOverride FileInfo AuthConfig Limit Indexes

33 Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

34 Require method GET POST OPTIONS

35

"/etc/httpd/conf.d/userdir.conf" 36L, 1254C 已写入

第2步:在用户家目录中建立用于保存网站数据的目录及首页面文件。另外,还需要把家目录的权限修改为755,保证其他人也有权限读取里面的内容。

[aa@master1-192-168-117-18 ~]$ mkdir public_html

[aa@master1-192-168-117-18 ~]$ echo "世界那么大,我出去看看!" > public_html/index.html

[aa@master1-192-168-117-18 ~]$ chmod -Rf 755 /home/aa/

第3步:重新启动httpd服务程序,在浏览器的地址栏中输入网址,其格式为“网址/~用户名”(其中的波浪号是必需的,而且网址、波浪号、用户名之间没有空格),从理论上来讲就可以看到用户的个人网站了。不出所料的是,系统显示报错页面,如图10-9所示。这一定还是SELinux惹的祸。

第4步:使用getsebool命令查询并过滤出所有与HTTP协议相关的安全策略。其中,off为禁止状态,on为允许状态。

[root@master1-192-168-117-18 ~]# getsebool -a | grep http

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_ipa --> off

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

[root@master1-192-168-117-18 ~]# setsebool -P httpd_enable_homedirs=on

通过身份验证访问网页

第1步:先使用htpasswd命令生成密码数据库。-c参数表示第一次生成;后面再分别添加密码数据库的存放文件,以及验证要用到的用户名称(该用户不必是系统中已有的本地账户)。

[root@master1-192-168-117-18 ~]# htpasswd -c /etc/httpd/passwd aa

New password:

Re-type new password:

Adding password for user aa

第2步:第2步:编辑个人用户主页功能的配置文件。随后保存并退出配置文件,重启httpd服务程序即可生效。

[root@master1-192-168-117-18 ~]# vim /etc/httpd/conf.d/userdir.conf

1 #

2 # UserDir: The name of the directory that is appended onto a user's home

3 # directory if a ~user request is received.

4 #

5 # The path to the end user account 'public_html' directory must be

6 # accessible to the webserver userid. This usually means that ~userid

7 # must have permissions of 711, ~userid/public_html must have permissions

8 # of 755, and documents contained therein must be world-readable.

9 # Otherwise, the client will only receive a "403 Forbidden" message.

10 #

11

12 #

13 # UserDir is disabled by default since it can confirm the presence

14 # of a username on the system (depending on home directory

15 # permissions).

16 #

17 # UserDir disabled

18

19 #

20 # To enable requests to /~user/ to serve the user's public_html

21 # directory, remove the "UserDir disabled" line above, and uncomment

22 # the following line instead:

23 #

24 UserDir public_html

25

26

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

32 AllowOverride all

33 authuserfile "/etc/httpd/passwd"

34 authname "My privately website"

35 authtype basic

36 require user aa

37

38

"/etc/httpd/conf.d/userdir.conf" 38L, 1217C 已写入

Linux添加网站后无法显示,Linux:SElinux导致网站无法访问相关推荐

  1. linux添加文件后无法启动,linux安装后grub无法启动

    解决办法如下: 使用启动优盘启动后 1.查看分区情况 sudo fdisk -lu /dev/sda 显示如下: Disk /dev/sda: 500.1 GB, 500107862016 bytes ...

  2. linux添加用户后怎么查看,linux怎样查看系统新添加的用户?

    linux怎样查看系统新添加的用户? 答案:4  信息版本:手机版 解决时间 2019-10-06 23:42 已解决 2019-10-06 06:26 如题!老板把服务器让别人配的,但是现在屡次发生 ...

  3. 会声会影2023如何添加字幕 会声会影添加字幕后不显示

    会声会影2023旗舰版是一款很实用的视频编辑软件,适合用于视频的后期制作.在后期制作中,添加字幕是很重要的环节.而会声会影的字幕编辑功能非常强大,可直接编辑.导入以及批量添加.下面我们一起来了解下会声 ...

  4. redhat6.5版本虚拟机添加网卡后不显示解决办法

    redhat6.5版本虚拟机添加网卡后不显示 明明添加了网卡,但却不显示,只显示一个eth0,没有新添加的eth1 具体解决办法: 1.找到eth1 的mac地址:ATTR{address}==&qu ...

  5. Android 系统,Wifi连接后,显示wifi已连接但无法访问网络。

    7.1系统8.0系统,Wifi连接后,显示wifi已连接但无法访问网络. 原因: 连接wifi后,会访问google服务器,由于国内访问不了,所以会显示"wifi已连接,但无法访问网络&qu ...

  6. linux输入ls后不显示_零基础学习之Linux基础命令小结

    安装完重启后,没有像sery所说在图形界面崩溃了,由于我没有安装X-WINDOWS而是直接进入了文本界面.如果你想做linux管理的话,最好在文本界面下工作,这样会适应如下图: 第一行显示的是我们所安 ...

  7. Linux添加/删除用户和用户组(linux中,添加cvs用户,实质就是添加linux用户。)

    来源:http://www.cnblogs.com/xd502djj/archive/2011/11/23/2260094.html 本文总结了Linux添加或者删除用户和用户组时常用的一些命令和参数 ...

  8. linux添加硬盘分区设置柱面,Linux添加硬盘并分区格式化

    一.Linux的硬盘识别 2.6 kernel以后,linux会将识别到的硬件设备,在/dev/下建立相应的设备文件.如: sda        表示第1块SCSI硬盘. hda        表示第 ...

  9. linux文本分割符怎么显示,Linux自定义分隔符IFS引发的文本处理问题

    需求是检查指定应用的某些配置所以就写了个脚本,数据文件的内容是这样的:应用名称|IP|端口    多个IP用空格,这样可以生成数组.这个文件的数据是通过部署平台的API获取后自己组装的. #!/bin ...

最新文章

  1. VLC架构及流程分析
  2. C51位运算应用技巧
  3. Xcode 环境变量(绝对路径与相对路径)
  4. TZOJ 4865 统计单词数(模拟字符串)
  5. 【循序渐进学Python】7.面向对象的核心——类型(上)
  6. 51nod 1412 AVL数的种类(DP
  7. android 观察者,Android开发实现简单的观察者与被观察者示例
  8. c++制表符_在Linux命令行中将制表符(tab)转换为空格
  9. python correlation_相关性系数介绍+python代码实现 correlation analysis
  10. 【C语言】【笔记】ASCII码值表;常用转义字符表
  11. 遗传算法matlab_通俗易懂地解释遗传算法
  12. 2017关于自学PHP的方法
  13. 系统备份和还原(固态系统盘)
  14. 我玩的王者荣耀(一)——鲁班
  15. SPA项目开发之CRUD+表单验证
  16. 计算机网络DNS域名解析协议详解
  17. 押宝ACE平台 北电自救或转身服务型公司
  18. 泰萌主今天怎么显示服务器异常,泰萌主网络请求错误怎么办?泰萌主怎么看不了了?...
  19. C语言 N个人围圈报数,数到3退出
  20. Oracle/PLSQL登录oracle时出现 ORA-12638 Credential retrieval failed错误

热门文章

  1. 搜狗输入法Android5.1,ESXI 服务器断电之后一直 LOADING MODULE IPMI_SI_DRV 的解决办法...
  2. Beta冲刺(9/7)——2019.5.31
  3. 微信小程序—day01
  4. 贝叶斯原理及其推断简介
  5. ubuntu软件(查看文件差异)
  6. 广州.NET俱乐部 VSTS活动报道
  7. 996. Number of Squareful Arrays
  8. 数据结构五——二叉树
  9. python入口函数的作用_python之函数中参数的作用域
  10. mysql-plus多数据库_Springboot+mybatisplus+mysql配置多数据源(注解版)