要求如下:
- 建立一个使用web服务器默认端口的网站,设置DocumentRoot为/www/port/80,网页内容为:the port is 80。
- 建立一个使用10000端口的网站,设置DocumentRoot为/www/port/10000,网页内容为:the port is 10000。
注:此时子配置不必再监听80端口
准备工作:web服务器搭建
第一步:挂载
[root@localhost node1]# mount /dev/sr0 /mnt/
第二步:编辑配置文件
[root@localhost node1]# vim /etc/yum.repos.d/web.repo
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
gpgcheck=0
第三步:安装软件包
[root@localhost node1]# dnf install httpd -y
[root@localhost ~]# rpm -ql httpd
[root@localhost httpd]# tree /etc/httpd
/etc/httpd
├── conf
│ ├── httpd.conf
│ └── magic
├── conf.d
│ ├── autoindex.conf
│ ├── README
│ ├── userdir.conf
│ └── welcome.conf
├── conf.modules.d
│ ├── 00-base.conf
│ ├── 00-dav.conf
│ ├── 00-lua.conf
│ ├── 00-mpm.conf
│ ├── 00-proxy.conf
│ ├── 00-systemd.conf
│ └── 01-cgi.conf
├── logs -> ../../var/log/httpd
├── modules -> ../../usr/lib64/httpd/modules
└──
run -> /run/httpd
第四步:启动httpd
[root@localhost node1]# systemctl start httpd.service
注:
1、启动用start,再次启动用restart,
2、.service后缀可加可不加
查看配置文件:
[root@localhost node1]# rpm -ql httpd | grep etc
第五步:设置防火墙状态:
[root@localhost ~]# systemctl status firewalld
[root@localhost ~]#systemctl stop firewalld
#可不用
[root@localhost ~]#systemctl disable firewalld
注意: systemctl start/restart/enable/disable/stop/status/reload 的区别
重启服务:
[root@localhost ~]# systemctl restart httpd
查看状态:
查看是否启动成功:
[root@localhost node1]# systemctl is-active httpd
active
##测试状态代码
[root@localhost node1]# systemctl stop httpd.service
[root@localhost node1]# systemctl is-active httpd
inactive
第六步:测试
- 在客户端:curl http://ip地址, curl -I 可以查看http报文信息
- 通过浏览器访问http://ip地址
第一步、启动httpd
[root@localhost node1]# systemctl start httpd.service
注:
1、启动用start,再次启动用restart,
2、.service后缀可加可不
第二步、设置防火墙状态:
[root@localhost ~]# systemctl status firewalld
[root@localhost ~]#systemctl stop firewalld
##也可用这个命令
[root@localhost ~]#systemctl disable firewalld
注意: systemctl start/restart/enable/disable/stop/status/reload 的区别
默认防火墙建立22端口连接
关闭文件访问权限——SeLinux
[root@localhost html]# setenforce 0
注:临时生效命令
第三步,定义基于不同端口来访问网站的配置文件
示例文件:
[root@localhost node1]# rpm -ql httpd | grep vhosts.conf
/usr/share/doc/httpd/httpd-vhosts.conf
[root@localhost node1]# vim /usr/share/doc/httpd/httpd-vhosts.conf
[root@localhost node1]# vim /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost 192.168.17.171:80>
ServerName 192.168.17.171
DocumentRoot /www/port/80
</VirtualHost>
LISTEN 10000
<VirtualHost 192.168.17.171:10000>
ServerName 192.168.17.171
DocumentRoot /www/port/10000
</VirtualHost>
<Directory /www>
AllowOverride none
Require all granted
</Directory>
第四步,创建两个网页文件根目录,并定义网页内容
[root@localhost ~]# mkdir -pv /www/port/{80,10000}
[root@localhost ~]# echo the port is 80 > /www/port/80/index.html
[root@localhost ~]# echo the port is 10000 > /www/port/10000/index.html
[root@localhost node1]# curl 192.168.17.171:80
the port is 80
[root@localhost node1]# curl 192.168.17.171:10000
the port is 10000
第五步:测试