httpd编译和配置三种风格不同的虚拟主机
httpd编译安装:
安装编译器和所需要的配置和工具
dnf -y install gcc gcc-c++ pcre-devel zlib-devel openssl
openssl-devel make expat-devel libtool
通过xftp将文件传输到虚拟机上 三个依赖包

解压

1.6.1,httpd-2.4.43
检测apr-1.7.0的编译环境



apr-util 1.6.1
[root@zwy1 ~]# cd apr-util-1.6.1
[root@zwy1 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #告知apr位置
配置忽略过程...
[root@zwy1 apr-util-1.6.1]# make
安装忽略过程...
[root@zwy1 apr-util-1.6.1]# make install
忽略过程
httpd 2.4.43
[root@zwy1 ~]# cd httpd-2.4.43
[root@zwy1 httpd-2.4.43]# ./configure --prefix=/usr/local/apache \ #编译
> --sysconfdir=/etc/httpd24 \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
# 配置模块编译
[root@zwy1 httpd-2.4.43] make
安装忽略过程..
[root@zwy1 httpd-2.4.43]make install
忽略过程
[root@zwy1 httpd-2.4.43]
将以下代码写在httpd.service文件中并存放在etc/systemd/system/目录下
[root@localhost system]# vim /etc/systemd/system/httpd.service Description=Start httpd [Service] Type=simple
EnvironmentFile=/etc/httpd24/httpd.conf
ExecStart=/usr/local/apache/bin/httpd -k start -DFOREGROUND ExecReload=/usr/local/apache/bin/httpd -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
[Install]
WantedBy=multi-user.target
关闭防火墙
[root@zwy1 httpd-2.4.43]# systemctl stop firewalld
启动apache
[root@zwy ~]# systemctl start httpd
[root@zwy1 ~]# systemctl status httpd
● httpd.service
Loaded: loaded (/etc/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-04-27 19:40:53 CST; 3h 19min ago
Main PID: 1715 (httpd)
Tasks: 9 (limit: 4747)
Memory: 6.9M
CGroup: /system.slice/httpd.service
├─1715 /usr/local/apache/bin/httpd -k start -DFOREGROUND
├─2478 /usr/local/apache/bin/httpd -k start -DFOREGROUND
├─2479 /usr/local/apache/bin/httpd -k start -DFOREGROUND
├─2480 /usr/local/apache/bin/httpd -k start -DFOREGROUND
├─2481 /usr/local/apache/bin/httpd -k start -DFOREGROUND
├─2482 /usr/local/apache/bin/httpd -k start -DFOREGROUND
├─2489 /usr/local/apache/bin/httpd -k start -DFOREGROUND
├─2490 /usr/local/apache/bin/httpd -k start -DFOREGROUND
└─2491 /usr/local/apache/bin/httpd -k start -DFOREGROUND
Apr 27 19:40:53 zwy1 systemd[1]: /etc/systemd/system/httpd.service:1: Assignment outside of section. Ignoring.
Apr 27 19:40:53 zwy1 systemd[1]: Started httpd.service.
Apr 27 19:41:08 zwy1 httpd[1715]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::ef03:c317:875d:2578%ens160. Set the 'ServerName' dire>
lines 1-20/20 (END)
用ip访问

配置虚拟主机:
虚拟主机有三类
相同IP不同端口
不同IP相同端口
相同IP相同端口不同域名
修改主配置文件httpd.conf

在/usr/local/apache/htdocs/下新建site1,2,3目录 ,目录下创建三个文件 echo依次写入

相同ip不同端口虚拟主机的配置文件
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/site1" #文件目录
ServerName zwy1.example.com #域名
ErrorLog "logs/zwy1.example.com-error_log" #错误日志文件
CustomLog "logs/zwy1.example.com-access_log" common #定制日志文件
</VirtualHost>>
listen 81
<VirtualHost *:81>
DocumentRoot "/usr/local/apache/htdocs/site2"
ServerName site2.example.com
ErrorLog "logs/site2.example.com-error_log"
CustomLog "logs/site2.example.com-access_log" common
</VirtualHost>
重启服务 apachectl restart
演示
80

81

不同ip 相同端口
先给ens160添加ip
[root@zwy1 htdocs]# ip addr add 192.168.59.129/24 dev ens160
[root@zwy1 htdocs]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:dd:22:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.59.128/24 brd 192.168.59.255 scope global dynamic noprefixroute ens160
valid_lft 1709sec preferred_lft 1709sec
inet 192.168.59.129/24 scope global secondary ens160
valid_lft forever preferred_lft forever
inet6 fe80::ef03:c317:875d:2578/64 scope link noprefixroute
valid_lft forever preferred_lft forever
配置文件
<VirtualHost 192.168.59.128:80>
DocumentRoot "/usr/local/apache/htdocs/site1"
ServerName site1.example.com
ErrorLog "logs/site1.example.com-error_log"
CustomLog "logs/site1.example.com-access_log" common
</VirtualHost>
<VirtualHost 192.168.59.129:80>
DocumentRoot "/usr/local/apache/htdocs/site2"
ServerName site2.example.com
ErrorLog "logs/site2.example.com-error_log"
CustomLog "logs/site2.example.com-access_log" common
</VirtualHost>
演示


相同ip相同端口不同域名的配置
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/site1"
ServerName site1.example.com
ErrorLog "logs/site1.example.com-error_log"
CustomLog "logs/site1.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/site2"
ServerName site2.example.com
ErrorLog "logs/site2.example.com-error_log"
CustomLog "logs/site2.example.com-access_log" common
</VirtualHost>
由于是假域名
通过以下方式
可以域名访问



浙公网安备 33010602011771号