linux:SElinux的实验

linux:SElinux的实验

​ 1.设定一台主机的主机名未webserver.timinglee.org
ip: 172.25.254.100
请打开此主机的selinux,并在系统中检测selinux的状态为enforcing(以上内容需要在报告中体现过程)
​ 2.配置nginx服务,要求其默认发布目录为/nginx/html默认发布内容为:webserver.timinglee.org
使用端口为:6666

​ 3.检测上述要求并把检测解决呈现在报告中

[root@server100 ~]# hostnamectl hostname webserver.timinglee.org

[root@server100 ~]# hostname
webserver.timinglee.org

# 关闭防火墙
[root@webserver ~]# systemctl disable --now firewalld.service
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".


[root@webserver ~]# ifconfig | tr -s " " | grep broadcast | cut -d " " -f3
172.25.254.100

# 永久开启selinux,需要重启系统生效
[root@webserver ~]# grubby --update-kernel ALL --args selinux=1

# 重启系统
[root@webserver ~]# reboot

# 查看seLinux的状态
[root@webserver ~]# getenforce
Enforcing

# 安装nginx软件并开启服务
[root@webserver ~]# dnf install nginx -y
[root@webserver ~]# systemctl enable --now nginx.service

# 修改nginx的主配置文件
[root@webserver ~]# vim /etc/nginx/nginx.conf
server {
        listen       6666;
        listen       [::]:80;
        server_name  _;
#      修改网页默认发布路径
        root         /nginx/html;

# 建立网页存储目录并制作网页文件
[root@webserver ~]# mkdir -p /nginx/html
[root@webserver ~]# mkdir -p /nginx/html

# 配置seLinux使其可以运行上述nginx的配置

##查看支持httpd的文件的安全上下文
[root@webserver ~]# ls -Zd /usr/share/nginx/html/index.html
system_u:object_r:httpd_sys_content_t:s0 /usr/share/nginx/html/index.html

# 修改自定义网页存储路径的安全上下文策略
[root@webserver ~]# semanage fcontext -a -t httpd_sys_content_t '/nginx/html(/.*)?'
[root@webserver ~]# restorecon -RvvF /nginx/html/
Relabeled /nginx/html from unconfined_u:object_r:default_t:s0 to system_u:object_r:httpd_sys_content_t:s0
Relabeled /nginx/html/index.html from unconfined_u:object_r:default_t:s0 to system_u:object_r:httpd_sys_content_t:s0

# 添加httpd服务支持的端口号
[root@webserver ~]# semanage port -a -t http_port_t -p tcp 6666

# 查看httpd服务的端口号
[root@webserver ~]# semanage  port -l  |  grep  http_port_t
http_port_t                    tcp      6666, 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t            tcp      5988

# 重启nginx服务,无报错
[root@webserver ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@webserver ~]# systemctl restart nginx.service

# 访问测试
[root@webserver ~]# curl 172.25.254.100:6666
webserver.timinglee.org
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值