编译安装httpd并配置服务器

实验需求
一.编译安装httpd
二.配置三种不同风格的虚拟主机

实验步骤

一.编译安装httpd

①.安装开发环境

[root@server ~]# yum -y groupinstall "Development Tools"
[root@server ~]# yum -y install openssl-devel pcre-devel expat-devel libtool

②.安装apr,apr-utils

[root@server opt]# tar -xf apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.34.tar.bz2 
[root@server opt]# ls
apr-1.6.3          apr-util-1.6.1          httpd-2.4.34
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.34.tar.bz2

[root@server opt]# cd apr-1.6.3/
[root@server apr-1.6.3]# vim configure
    # $RM "$cfgfile"
[root@server apr-1.6.3]# ./configure --prefix=/usr/local/apr 
[root@server apr-1.6.3]# make && make install


[root@server opt]# cd apr-util-1.6.1/
[root@server apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@server apr-util-1.6.1]# make && make install

③.安装httpd

[root@server apr-util-1.6.1]# cd /opt/httpd-2.4.34/
[root@server httpd-2.4.34]#  ./configure --prefix=/usr/local/apache \
> --sysconfdir=/etc/httpd123 \
> --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@server httpd-2.4.34]# make && make install



二.配置三种不同风格的虚拟主机

1.相同ip,不同端口

①.修改配置文件/etc/httpd123/httpd.conf,新增下面的内容

[root@server httpd-2.4.34]# vim /etc/httpd123/httpd.conf 
Listen 8000
erverName www.example.com:80
<VirtualHost 172.16.11.13:80>
        ServerName www.xixi.com
        DocumentRoot "/usr/local/httpd/htdocs/xixi"
        ErrorLog "/usr/local/httpd/logs/error1_log"
        CustomLog "/usr/local/httpd/logs/access1_log" combined
                <Directory /usr/local/httpd/htdocs/xixi>
                        Require all granted
                </Directory>
</VirtualHost>


<VirtualHost 172.16.11.13:8000>
        ServerName www.hehe.com
        DocumentRoot "/usr/local/httpd/htdocs/hehe"
        ErrorLog "/usr/local/httpd/logs/error2_log"
        CustomLog "/usr/local/httpd/logs/access2_log" combined
                <Directory /usr/local/httpd/htdocs/hehe>
                        Require all granted
                </Directory>
</VirtualHost>

②.为了使用方便,将启动命令apachectl路径写入PATH路径

[root@server httpd-2.4.34]# vim /etc/profile.d/httpd.sh 
export PATH=/usr/local/httpd/bin:$PATH

验证结果
①.查看有没有语法错误,没有就启动服务

[root@server httpd-2.4.34]# httpd -t
Syntax OK
[root@server httpd-2.4.34]# apachectl restart

在这里插入图片描述
在这里插入图片描述



2.不同ip,相同端口
①.修改/etc/httpd123/http.conf配置文件

[root@server httpd-2.4.34]# vim /etc/httpd123/httpd.conf 
<VirtualHost 172.16.11.13:80> 
        ServerName www.xixi.com
        DocumentRoot "/usr/local/httpd/htdocs/xixi"
        ErrorLog "/usr/local/httpd/logs/error1_log"
        CustomLog "/usr/local/httpd/logs/access1_log" combined
                <Directory /usr/local/httpd/htdocs/xixi>
                        Require all granted
                </Directory>
</VirtualHost>


<VirtualHost 172.16.11.14:80>
        ServerName www.hehe.com
        DocumentRoot "/usr/local/httpd/htdocs/hehe"
        ErrorLog "/usr/local/httpd/logs/error2_log"
        CustomLog "/usr/local/httpd/logs/access2_log" combined
                <Directory /usr/local/httpd/htdocs/hehe> 
                        Require all granted
                </Directory>
</VirtualHost>
"/etc/httpd123/h

②.给网卡新增一个ip

[root@server httpd-2.4.34]# ip addr add 172.16.11.14/24 dev ens33

[root@server httpd-2.4.34]# ip a s ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:56:9d:42 brd ff:ff:ff:ff:ff:ff
    inet 172.16.11.13/24 brd 172.16.11.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 172.16.11.14/24 scope global secondary ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::462d:9cc2:ac18:98d0/64 scope link 
       valid_lft forever preferred_lft forever

结果验证
在这里插入图片描述
在这里插入图片描述



3.相同ip相同端口,不同域名

①.修改配置文件

[root@server httpd-2.4.34]# vim /etc/httpd123/httpd.conf 
<VirtualHost 172.16.11.13:80>
        ServerName www.xixi.com
        DocumentRoot "/usr/local/httpd/htdocs/xixi"
        ErrorLog "/usr/local/httpd/logs/error1_log"
        CustomLog "/usr/local/httpd/logs/access1_log" combined
                <Directory /usr/local/httpd/htdocs/xixi>
                        Require all granted
                </Directory>
</VirtualHost>
      

<VirtualHost 172.16.11.13:80>
        ServerName www.hehe.com
        DocumentRoot "/usr/local/httpd/htdocs/hehe"
        ErrorLog "/usr/local/httpd/logs/error2_log"
        CustomLog "/usr/local/httpd/logs/access2_log" combined
                <Directory /usr/local/httpd/htdocs/hehe>
                        Require all granted
                </Directory>
</VirtualHost>

验证结果
①.使用windows测试,修改C:/Windows/System3/drivers/etc/hosts文件,需要用到工具notepad++,可以手动下载,添加以下两条

172.16.11.13 www.xixi.com
172.16.11.13 www.hehe.com

在这里插入图片描述
在这里插入图片描述

报错解决
一.编译安装httpd,make时候报错

collect2: error: ld returned 1 exit status
make[2]: [htpasswd] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.33/support”
make[1]: [all-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.33/support”
make: [all-recursive] 错误 1

解决
将apr和apr-util解压出来的包拷贝到httpd解压出来的包下面的srclib目录下面,需要新建arp和apr-util,拷贝到里面,然后./configure最后加上-with-included-apr这一参数

cp -r apr-1.6.3 /usr/local/src/httpd-2.4.33/srclib/apr 
cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.33/srclib/apr-util

./configure --prefix=/usr/local/apache \
> --sysconfdir=/etc/httpd123 \
> --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
> --with-included-apr

猜你喜欢

转载自blog.csdn.net/weixin_43154788/article/details/82755422