编译安装httpd
[root@wangxiaolan ~]# yum groupinstall "Development Tools"
[root@wangxiaolan ~]# groupadd -r apache
[root@wangxiaolan ~]# useradd -r -g apache apache
[root@wangxiaolan ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
下载并安装apr-1.4+和apr-util-1.4+
[root@wangxiaolan ~]# cd /usr/src/
[root@wangxiaolan src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.5.tar.bz2
[root@wangxiaolan src]# ls
apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 debug kernels
[root@wangxiaolan src]# tar xf apr-1.6.5.tar.bz2
[root@wangxiaolan src]# tar xf apr-util-1.6.1.tar.bz2
[root@wangxiaolan src]# ls
apr-1.6.5 apr-1.6.5.tar.bz2 apr-util-1.6.1 apr-util-1.6.1.tar.bz2 debug kernels
[root@wangxiaolan src]# cd apr-1.6.5
[root@wangxiaolan apr-1.6.5]# vim configure
[root@wangxiaolan ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.37.tar.bz2
[root@wangxiaolan ~]## ls
httpd-2.4.37.tar.bz2
[root@wangxiaolan ~]# tar xf httpd-2.4.37.tar.bz2
[root@wangxiaolan ~]# cd httpd-2.4.37
[root@wangxiaolan httpd-2.4.37]# ./configure --prefix=/usr/local/apache \
[root@wangxiaolan httpd-2.4.37]# make && make install
配置虚拟主机
1.设置主机名,配置文件取消servername行前面的#号
[root@wangxiaolan ~]# vim /etc/httpd/conf/httpd.conf
......
ServerAdmin root@localhost
## ServerName gives the name and port that the server uses to identify itself.# This can often be determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## If your host doesn't have a registered DNS name, enter its IP address here.#
ServerName www.example.com:80
......
虚拟主机1的配置
[root@wangxiaolan ~]# vim /etc/httpd/conf/httpd.conf//在配置文件的最后加上如下内容#
<VirtualHost 172.16.30.12:80>
ServerName www.wxl.com
DocumentRoot "/var/www/html/www"
ErrorLog "/var/log/httpd/www/error_log"
CustomLog "/var/log/httpd/www/access_log" combined
<Directory /var/www/html/www>
<RequireAll>
Require all granted
Require not ip 192.168.1
</RequireAll>
</Directory>
虚拟主机2的配置
[root@wangxiaolan ~]# vim /etc/httpd/conf/httpd.conf
</VirtualHost># virtual host 2
<VirtualHost 172.16.30.12:80>
ServerName blog.wxl.com
DocumentRoot "/var/www/html/blog"
ErrorLog "/var/log/httpd/blog/error_log"
CustomLog "/var/log/httpd/blog/access_log" combined
<Directory /var/www/html/blog>
<RequireAll>
Require all granted
</RequireAll>
</Directory>
</VirtualHost>
2.创建网页目录并修改属主属组
[root@wangxiaolan ~]# cd /var/www/html/
[root@wangxiaolan html]# ls
[root@wangxiaolan html]# mkdir www blog
[root@wangxiaolan html]# ll
total 0
drwxr-xr-x 2 root root 6 Aug 5 16:56 blog
drwxr-xr-x 2 root root 6 Aug 5 16:56 www
[root@wangxiaolan html]# chown -R apache.apache blog
[root@wangxiaolan html]# chown -R apache.apache www
[root@wangxiaolan html]# ll
total 0
drwxr-xr-x 2 apache apache 6 Aug 5 16:56 blog
drwxr-xr-x 2 apache apache 6 Aug 5 16:56 www
3.创建网页
[root@wangxiaolan html]# pwd
/var/www/html
[root@wangxiaolan html]# ls
blog www
[root@wangxiaolan html]# echo 'hello welcome to visit www' > www/index.html
[root@wangxiaolan html]# echo 'hello welcome to visit blog' > blog/index.html
4.创建相应网页的日志目录
[root@wangxiaolan ~]# mkdir /var/log/httpd/{www,blog}
[root@wangxiaolan ~]# ll /var/log/httpd/
total 0
drwxr-xr-x 2 root root 6 Aug 5 09:11 blog
drwxr-xr-x 2 root root 6 Aug 5 09:11 www
[root@wangxiaolan ~]# chown -R apache.apache /var/log/httpd/
5.启动服务并查看是否有80端口
[root@wangxiaolan ~]# systemctl start httpd
[root@wangxiaolan ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
6.在客户机上验证修改hosts文件
[root@wangxiaolan ~]#vim /etc/hosts
~ cat /etc/hosts
#
#
# Host Database#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
118.31.33.0 zabbix.forevercq.com
0.0.0.0 account.jetbrains.com
//添加以下2行
172.16.30.12 www.wxl.com
172.16.30.12 blog.wxl.com