一、搭建静态网站
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl status firewalld
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#systemctl disable firewalld
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# echo hello world > /var/www/html/index.html
[root@localhost ~]# curl 192.168.126.140
hello world
二、建立两个基于ip地址访问的网站,要求如下:
1、该网站ip地址的主机位为100,设置DocumentRoot为/www/ip/100,网页内容为:this is 100。
2、该网站ip地址主机位为200,设置DocumentRoot为/www/ip/200,网页内容为:this is 200。
第一步,先添加两个ip地址
[root@localhost ~]#nmcli connection modify eno16777736 +ipv4.addresses 192.168.126.100/24 ipv4.gateway 192.168.126.1
[root@localhost ~]# nmcli connection modify eno16777736 +ipv4.addresses 192.168.126.200/24
[root@localhost ~]# nmcli connection up eno16777736
第二步,创建两个网页文件根目录,并定义网页内容
[root@localhost ~]# mkdir -pv /www/ip/{100,200}
[root@localhost ~]# echo this is 100 > /www/ip/100/index.html
[root@localhost ~]# echo this is 200 > /www/ip/200/index.html
[root@server html]# setenforce 0
[root@server html]# getenforce
Permissive
第三步,定义基于不同ip地址来访问网站的配置文件
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# curl 192.168.126.200
this is 200
[root@localhost ~]# curl 192.168.126.100
this is 100
如果访问时显示的是apache默认的欢迎界面,则需要做如下操作:
[root@localhost ~]# setenforce 0
三、搭建静态网站——基于https协议的静态网站
[root@localhost ~]# yum install mod_ssl -y
[root@localhost ~]# cd /etc/pki/tls/certs/
[root@localhost certs]# make jiami.crt
[root@localhost ~]# vim /etc/httpd/conf.d/host.conf
<VirtualHost 192.168.80.128 >
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/jia.crt
SSLCertificateKeyFile /etc/pki/tls/certs/jia.crt
DocumentRoot /www/https
ServerName 192.168.80.128
<directory /www/https>
allowoverride none
require all granted
[root@localhost ~]# systemctl restart httpd
通过浏览器访问或者curl --insecure https://IP地址