web基础与http协议

打开虚拟机


安装软件包

dnf install -y apr-util-devel pcre-devel gcc tar make

解压压缩包

tar zxf httpd-2.4.48.tar.gz -C /usr/src

进入压缩包目录

cd /usr/src/httpd-2.4.25/

配置文件

./configure --prefix=/usr/local/http --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

编译安装

make && make install

优化执行路径

ln -s /usr/local/httpd/bin/* /usr/local/bin

验证结果

httpd -v

添加系统服务

cd /lib/systemd/system vi httpd.service [Unit] Description=The Apache HTTP Server After=network.target [Service] Type=forking PIDFile=/usr/local/httpd/logs/httpd.pid ExecStart= /usr/local/bin/apachectl $OPTIONS ExecrReload= /bin/kill -HUP $MAINPID PrivatTmp=true [Install] Wanted By=multi-user.target

开机启动

systemctl enable httpd.service

配置并且启动http服务

vi /usr/local/http/conf/httpd.conf ServerName www.example.com:80 删除#号 apachectl start ss -nlpt | grep httpd

使用虚拟机建立多个网站

mkdir -p /var/www/html/kgccom 创建网页根目录 mkdir -p /var/www/html/kccecom echo "<h1>www.kgc.com</h1>"> /var/www/html/kgccom/index.html echo "<h1>www.kcce.com</h1>"> /var/www/html/kccecom/index.html

修改虚拟机主机配置文件

vi /usr/local/http/conf/extra/httpd-vhosts.conf <VirtualHost *:80> //设置 kgc 虚拟站点区域 DocumentRoot "/var/www/html/kgccom" ServerName www.kgc.com ErrorLog "logs/www.kgc.com.error_log" CustomLog "logs/www.kgc.com.access_log" common </VirtualHost> <VirtualHost *:80> //设置 kcce 虚拟站点区域 DocumentRoot "/var/www/html/kccecom" ServerName www.kcce.com ErrorLog "logs/www.kcce.com.error_log" CustomLog "logs/www.kcce.com.access_log" common </VirtualHost> <Directory "/var/www/html"> //设置目录访问权限 Require all granted </Directory>

修改配置文件

vi /usr/local/http/conf/httpd.conf Include conf/extra/httpd-vhosts.conf

重启

apachectl restart

验证

修改客户机hosts文件

vi /etc/hosts 192.168.255.128 www.kgc.com

192.168.255.128 www.kcce.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值