一、 安装apache
有需要的话,可以去查看具体的apache的安装apache安装https://blog.csdn.net/m0_68472908/article/details/139348739?spm=1001.2014.3001.5501
都可以使用本地yum源搭建本地yum源搭建https://blog.csdn.net/m0_68472908/article/details/143856929?spm=1001.2014.3001.5501
- 安装组件
bash
yum install -y gcc gcc-c++ make apr apr-devel apr-util-devel pcre pcre-devel lrzsz
- 将源码包拖进Xshell内并解压
bash
tar zvxf httpd-2.4.59.tar.gz -C /usr/src/
- 编译安装源码包
bash
cd /usr/src/httpd-2.4.59/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install
- 优化执行路径
bash
ln -s /usr/local//httpd/bin/* /usr/local/bin/
- 复制apachectl脚本
bash
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
- 修改init.d文件内容,添加
bash
vim /etc/init.d/httpd
- 添加为系统服务
bash
chkconfig --add httpd
- 修改ServerName(一定要修改,不然开启会报错)
bash
vim /usr/local/httpd/conf/httpd.conf
- 开启服务
bash
service httpd start
- 关闭防火墙
bash
systemctl stop firewalld
setenforce 0
虚拟主机配置
相同IP、端口,不同域名
- 启用虚拟主机文件
bash
vim /usr/local/httpd/conf/httpd.conf
- 创建目录,并编写网页
bash
cd /usr/local/httpd/htdocs/
mkdir yjs bcnt
echo "www.yjs.com" > yjs/index.html
echo "www.bcnt.com" > bcnt/index.html
- 编辑虚拟主机文件(修改就行)
bash
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.180.110:80>
DocumentRoot "/usr/local/httpd/htdocs/yjs"
ServerName www.yjs.com
ErrorLog "logs/www.yjs.com-error_log"
CustomLog "logs/www.yjs.com-access_log" common
</VirtualHost>
<VirtualHost 192.168.180.110:80>
DocumentRoot "/usr/local/httpd/htdocs/bcnt"
ServerName www.bcnt.com
ErrorLog "logs/www.bcnt.com-error_log"
CustomLog "logs/www.bcnt.com-access_log" common
</VirtualHost>
- 修改hosts文件
bash
vim /etc/hosts
192.168.180.110 www.yjs.com
192.168.180.110 www.bcnt.com
- 重启服务
bash
apachectl restart
- 访问测试
bash
curl www.yjs.com
curl www.bcnt.com
不同IP,相同端口
- 添加虚拟网卡
bash
ifconfig ens33:0 192.168.180.111
- 修改虚拟主机文件
bash
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
- 重启服务
bash
apachectl restart
- 访问测试
bash
curl 192.168.180.110
curl 192.168.180.111
相同IP,不同端口
- 添加新端口
bash
vim /usr/local/httpd/conf/httpd.conf
- 修改虚拟主机文件
bash
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
- 重启服务
bash
apachectl restart
- 访问测试
bash
curl 192.168.180.110
curl 192.168.180.110:8080