挂载安装:
[root@localhost ~]# mkdir -p /media/cdrom
[root@localhost ~]# mount /dev/cdrom /media/cdrom
[root@localhost ~]# df –hv
[root@localhost ~]# vim /etc/fstab
/dev/cdrom /media/cdrom iso9660 defaults 0 0
[root@localhost ~]# vim /etc/yum.repos.d/rhel.repo
[rhel]
name=xiaolu
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
[root@localhost ~]# yum install httpd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# vim index.html
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
[root@localhost html]# mkdir /home/wwwroot
[root@localhost html]# systemctl restart httpd
[root@localhost html]# cd /home/wwwrooot
bash: cd: /home/wwwrooot: No such file or directory
[root@localhost html]# cd /home/wwwroot
[root@localhost wwwroot]# vim index.html
[root@localhost wwwroot]# vim /etc/selinux/config
[root@localhost wwwroot]# getenforce
Enforcing
[root@localhost wwwroot]# setenforce 0
[root@localhost wwwroot]# chmod -Rf 755
chmod: missing operand after ‘755’
Try 'chmod --help' for more information.
[root@localhost wwwroot]# vim /etc/httpd/conf/httpd.conf
[root@localhost wwwroot]# systemctl restart httpd
[root@localhost wwwroot]# setenforce 1
[root@localhost wwwroot]# setenforce 0
[root@localhost wwwroot]# setenforce 1
[root@localhost wwwroot]# ls -ldZ /var/www/html
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
[root@localhost wwwroot]# ls -ldZ /home/wwwroot
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/*
[root@localhost wwwroot]# restorecon -Rv /home/wwwroot
[root@localhost wwwroot]# vim /etc/httpd/conf.d/userdir.conf
[root@localhost wwwroot]# systemctl restart httpd
[root@localhost wwwroot]# su - linuxprobe
[linuxprobe@localhost ~]$ mkdir public_html
[linuxprobe@localhost ~]$ cd public_html/
[linuxprobe@localhost public_html]$ vim index.html
[linuxprobe@localhost public_html]$ cd ..
[linuxprobe@localhost ~]$ chmod -Rf 755 ~
[linuxprobe@localhost ~]$ exit
logout
[root@localhost wwwroot]# setenforce 0
[root@localhost wwwroot]# setenforce 1
[root@localhost wwwroot]# getsebool -a
[root@localhost wwwroot]# getsebool -a | grep http
[root@localhost wwwroot]# setsebool -P httpd_enable_homedirs=on
[root@localhost wwwroot]# htpasswd -c /etc/httpd/passwd abel
[root@localhost wwwroot]# file /etc/httpd/passwd
[root@localhost wwwroot]# vim /etc/httpd/conf.d/userdir.conf
<Directory "/home/*/public_html">
allowoverride all
authuserfile /etc/httpd/passwd
authname ahahahahahahahahah
authtype basic
require user abel
</Directory>
[root@localhost wwwroot]# systemctl restart httpd
虚拟网站主机功能
基于IP地址
[root@localhost ~]# yum install httpd
[root@localhost home]# mkdir wwwroot
[root@localhost home]# mkdir -p /home/wwwroot
[root@localhost home]# mkdir -p /home/wwwroot/10
[root@localhost home]# mkdir -p /home/wwwroot/20
[root@localhost home]# mkdir -p /home/wwwroot/30
[root@localhost home]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728
ONBOOT=yes
IPADDR0=192.168.10.10
IPADDR1=192.168.10.20
IPADDR2=192.168.10.30
[root@localhost home]# systemctl restart network
[root@localhost home]# ping 192.168.10.10
[root@localhost home]# ping 192.168.10.20
[root@localhost home]# ping 192.168.10.30
[root@localhost home]# cd /home/wwwroot
[root@localhost wwwroot]# ls
10 20 30
[root@localhost wwwroot]# echo "101010101010101010" > 10/index.html
[root@localhost wwwroot]# echo "202020202020202020" > 20/index.html
[root@localhost wwwroot]# echo "303030303030303030" > 30/index.html
[root@localhost wwwroot]# vim /etc/httpd/conf/httpd.conf
<virtualhost 192.168.10.10>
documentroot /home/wwwroot/10
servername www.linuxprobe.com
<directory /home/wwwroot/10>
allowoverride none
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.10.20>
documentroot /home/wwwroot/20
servername www.linuxprobe.com
<directory /home/wwwroot/20>
</directory>
allowoverride none
require all granted
</virtualhost>
<virtualhost 192.168.10.30>
documentroot /home/wwwroot/30
servername www.linuxprobe.com
<directory /home/wwwroot/30>
</directory>
allowoverride none
require all granted
</virtualhost>
[root@localhost wwwroot]# systemctl restart httpd
[root@localhost wwwroot]# systemctl enable httpd
[root@localhost wwwroot]# ls -ldZ /var/www/html
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/10
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/10/*
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/20
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/20/*
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/30
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/30/*
[root@localhost wwwroot]# restorecon -Rv /home/wwwroot
[root@localhost wwwroot]# firefox
基于主机域名
[root@localhost ~]# yum install httpd
[root@localhost ~]# vim /etc/hosts
192.168.10.10 www.linuxprobe.com bbs.linuxprobe.com tech.linuxprobe.com
[root@localhost ~]# ping www.linuxprobe.com
[root@localhost ~]# ping bbs.linuxprobe.com
[root@localhost ~]# ping tech.linuxprobe.com
[root@localhost ~]# mkdir -p /home/wwwroot
[root@localhost ~]# mkdir -p /home/wwwroot/www
[root@localhost ~]# mkdir -p /home/wwwroot/bbs
[root@localhost ~]# mkdir -p /home/wwwroot/tech
[root@localhost wwwroot]# echo "wwwwwww" > www/index.html
[root@localhost wwwroot]# echo "techtech" > tech/index.html
[root@localhost wwwroot]# echo "bbsbbsbb" > bbs/index.html
[root@localhost wwwroot]# vim /etc/httpd/conf/httpd.conf
<virtualhost 192.168.10.10>
documentroot /home/wwwroot/www
servername www.linuxprobe.com
<directory /home/wwwroot/www>
allowoverride none
require all granetd
</directory>
</virtualhost>
<virtualhost 192.168.10.10>
documentroot /home/wwwroot/bbs
servername bbs.linuxprobe.com
<directory /home/wwwroot/bbs>
allowoverride none
require all granetd
</directory>
</virtualhost>
<virtualhost 192.168.10.10>
documentroot /home/wwwroot/tech
servername tech.linuxprobe.com
<directory /home/wwwroot/tech>
allowoverride none
require all granetd
</directory>
</virtualhost>
[root@localhost wwwroot]# systemctl restart httpd
[root@localhost wwwroot]# systemctl enable httpd
[root@localhost wwwroot]# ls -ldZ /var/www/html
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/www
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/www/*
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/bbs
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/bbs/*
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/tech
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/tech/*
[root@localhost wwwroot]# restorecon -Rv /home/wwwroot
[root@localhost wwwroot]# firefox
基于端口号
[root@localhost ~]# yum install httpd
[root@localhost ~]# mkdir -p /home/wwwroot/6111
[root@localhost ~]# mkdir -p /home/wwwroot/6333
[root@localhost ~]# cd /home/wwwroot
[root@localhost wwwroot]# echo "611111111111" > 6111/index.html
[root@localhost wwwroot]# echo "633333333333" > 6333/index.html
[root@localhost wwwroot]# vim /etc/httpd/conf/httpd.conf
Listen 6111
Listen 6222
<virtualhost 192.168.10.10:6111>
documentroot /home/wwwroot/6111
servername www.linuxprobe.com
<directory /home/wwwroot/6111>
allowoverride none
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.10.10:6222>
documentroot /home/wwwroot/6222
servername www.linuxprobe.com
<directory /home/wwwroot/6222>
allowoverride none
require all granted
</directory>
[root@localhost wwwroot]# systemctl restart httpd
Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.
--------------------------------à SElinux 服务检测到6111和6222端口
--------------------------------àSELinux安全上下文
[root@localhost wwwroot]# ls -ldZ /var/www/html
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6111
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6111/*
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6222
[root@localhost wwwroot]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6222/*
[root@localhost wwwroot]# semanage port -l
[root@localhost wwwroot]# semanage port -l | grep http
http_cache_port_t tcp 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
[root@localhost wwwroot]# semanage port -a -t http_port_t -p tcp 6111
[root@localhost wwwroot]# semanage port -a -t http_port_t -p tcp 6222
[root@localhost wwwroot]# semanage port -l | grep http
http_cache_port_t tcp 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 6222, 6111, 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
[root@localhost wwwroot]# systemctl restart httpd
[root@localhost wwwroot]# systemctl enable httpd
[root@localhost wwwroot]# restorecon -Rv /home/wwwroot