Apache程序是目前拥有最高市场占有率的web服务程序之一,其跨平台和安全普遍被承认且拥有快速、可靠、简单的API发展。下面是使用Apache服务部署静态网站html
一.1.咱们首先建立目录/media/cdrom,把光盘设配系统中镜像挂载到目录/media.cdrom命令为:linux
[root@localhost ~]# mkdir -p /media/cdrom
[root@localhost ~]# mount /dev/cdrom /media/cdrom/web
2.配置yum源文件,编辑yum源文件名称为rhel7,后缀名REPO不可缺乏命令为:数据库
[root@localhost ~]# vim /etc/yum.repos.d/rhel7.repovim
3.配置文件内容以下浏览器
4.安装http服务程序,命令为:安全
[root@localhost ~]# yum install httpd服务器
5.启动http服务,重启服务器命令为:tcp
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'网站
6.进入浏览器Firefox命令为:
[root@localhost ~]# firefox
7.进入浏览器,输入地址http://127.0.0.1,出现http默认页面如图所示
8.向/var/www/html/index.html中,写入文件I like linux,替换http服务默认页面命令为;[root@localhost ~]# echo "I like linux" > /var/www/html/index.html
9.进入浏览器Firefox
10.http服务器默认页面,替换成功
二.咱们下面进行创建网站数据
1.创建网站数据目录,并建立首页文件,给http服务程序的主配置文件,进行修改,吧119行和124行路径改成/home/wwwroot
[root@localhost ~]# mkdir /home/wwwroot
[root@localhost ~]# echo "I like linux" > /home/wwwroot/index.html
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
文件内容为
2..从新启动http服务程序并验证效果,可是页面显示仍是默认页面,由于是selinux,因此往下看
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# firefox
3.进入Linux系统文件,查看selinux服务主配置文件中定义的默认状态要为enforcing,如不是就修改成enforcing。Enforcing是强制启用安全策略模式,将拦截服务的不合法请求。
[root@localhost ~]# vim /etc/selinux/config
4.获取当前运行模式,为了确认上面的验证效果是否由于selinux所致使的,用setenforce 0命令修改selinux的运行模式,0为禁用1为启用,这只是临时的。验证页面效果,为正常页面,问题确实出现selinux服务上
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# firefox
5.如今把selinux服务恢复到强制启用安全策略模式,而后分别查看原始网站数据的保存目录与当前网站数据目录,二者有何不一样的selinux安全上文值。
[root@localhost ~]# setenforce 1
[root@localhost ~]# ls -Zd /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
[root@localhost ~]# ls -Zd /home/wwwroot/
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/wwwroot/
6.向新的网站数据目录添加一条selinux安全上下文,让这个目录及全部文件都被httpd服务访问到。
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/*
7.使用restorecon命令设置selinux安全上下文当即将生效,再加上-RV参数对指定的目录进行递归操做命令为:restorecon –RV /home/wwwroot(目录名称),登陆页面,页面为正常内容。
[root@localhost ~]# restorecon -Rv /home/wwwroot/
restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
[root@localhost ~]# firefox
三.设置我的用户主页功能
1.首先配置文件,将17行(表示http开启我的用户主页面)加上注释,24行(表示网站用户家目录中的保存目录)去掉注释。
[root@localhost ~]# vim /etc/httpd/conf.d/userdir.conf
2.切换到HOME目录下,建立用户linuxprobe ,.建立网站的首页文件,对家目录的权限修改成755,保证其余人也能读取内容。
[root@localhost home]# useradd linuxprobe
[root@localhost home]# su - linuxprobe
[linuxprobe@localhost ~]$ mkdir public_html
[linuxprobe@localhost ~]$ echo "I like linux" > public_html/index.html
[linuxprobe@localhost ~]$ chmod -Rf 755 /home/linuxprobe
3.重启服务,页面显示报错,又是selinux的错误。
4.使用getsebool命令查阅并过滤出全部与http协议相关的安全策略,off为禁止on为容许
[root@localhost ~]# 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_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
5.用到selinux域安全策略为http_enable_homedirs,用setsebool修改布尔值,-P为参数,对修改后的selinux策略规则永久生效。页面效果正常。
6..使用htpasswd命令生成密码数据库,-c第一次生成,而后分别添加密码,以及验证获得用户名称。
7.编辑我的用户主页功能的配置文件。31到35行.
8.重启服务,访问用户网站。网站需输入用户名和密码,用户名是上面建立的用户名。密码同上所设。