Linux下apache编译、配置使用

本文详细介绍了如何在Linux系统上编译安装ApacheHTTPServer2.4.54,包括解决依赖问题、配置选项以及设置虚拟主机,涵盖了基于不同IP地址、端口和域名的配置方法。此外,还提到了DNS服务在配置基于域名的虚拟主机中的作用。
摘要由CSDN通过智能技术生成

目录

一、编译源码

二、配置文件

基于不同IP地址

基于不同端口

 基于不同域名(需要有域名解析:DNS服务)


一、编译源码

1、解码

[root@localhost ~] tar -zxf httpd-2.4.54.tar.gz  #解码

2、配置

[root@localhost ~] cd httpd-2.4.54/  #进入文件目录
[root@localhost httpd-2.4.54]# ./configure --prefix=/usr/local/apache  #配置
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.   #逐步解决依赖问题
[root@localhost httpd-2.4.54] yum -y install apr apr-util apr-util-devel #下载依赖
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * c7-media: 
正在解决依赖关系


[root@localhost httpd-2.4.54] yum -y install gcc gcc-c++   #下载依赖
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * c7-media: 
正在解决依赖关系   

[root@localhost httpd-2.4.54] yum -y install pcre-devel zlib-devel  #继续解决依赖
  正在安装    : zlib-devel-1.2.7-18.el7.x86_64                              1/2 
  正在安装    : pcre-devel-8.32-17.el7.x86_64                               2/2 
  验证中      : pcre-devel-8.32-17.el7.x86_64                               1/2 
  验证中      : zlib-devel-1.2.7-18.el7.x86_64                              2/2 

已安装:
  pcre-devel.x86_64 0:8.32-17.el7        zlib-devel.x86_64 0:1.2.7-18.el7       

完毕!



[root@localhost httpd-2.4.54] ./configure --prefix=/usr/local/apache  #直到解析完成


已安装:
  gcc.x86_64 0:4.8.5-44.el7            gcc-c++.x86_64 0:4.8.5-44.el7   
    Server Version: 2.4.54
    Install prefix: /usr/local/apache
    C compiler:     gcc -std=gnu99
    CFLAGS:           -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E

        

3.编译、编译安装

[root@localhost httpd-2.4.54] make &&make install
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: 离开目录“/root/httpd-2.4.54”   #显示离开即可

二、配置文件

1.优化命令

[root@localhost ~] ln -s /usr/local/apache/bin/apachectl /usr/local/bin/apachectl
                    #方便使用命令

2.虚拟主机头

修改主配置文件

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 

3. 主配置文件包含虚拟主机配置文件 

基于不同IP地址

[root@localhost ~] vim /usr/local/apache/conf/extra/httpd-vhosts.conf


<VirtualHost 192.168.9.254:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/apache/htdocs/skl1"    #文件路径一定要对应,错了启动不了
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/9.254-error_log"
    CustomLog "logs/9.254-access_log" common
</VirtualHost>

<VirtualHost 192.168.10.254:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/local/apache/htdocs/skl2"
#    ServerName dummy-host2.example.com
    ErrorLog "logs/10.254-error_log"
    CustomLog "logs/10.254-access_log" common
</VirtualHost>

[root@localhost ~] cd /usr/local/apache/htdocs/
[root@localhost htdocs] mkdir skl1
[root@localhost htdocs] mkdir skl2
[root@localhost htdocs] cp index.html skl1
[root@localhost htdocs] cp index.html skl2
[root@localhost htdocs] rm index.html 
rm:是否删除普通文件 "index.html"?y
[root@localhost skl1] vim index.html #进去编写

 [root@localhost skl1] apachectl start #启动服务
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message




基于不同端口

 修改配置文件

[root@localhost extra] vim httpd-vhosts.conf  #修改包含虚拟机头主配置文件
<VirtualHost 192.168.9.254:8081>    #修改
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/apache/htdocs/skl1"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/8081-error_log"      #修改
    CustomLog "logs/8081-access_log" common   #修改
</VirtualHost>

<VirtualHost 192.168.10.254:8082>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/local/apache/htdocs/skl2"
#    ServerName dummy-host2.example.com
    ErrorLog "logs/8082-error_log"
    CustomLog "logs/8082.254-access_log" common
</VirtualHost>

 
[root@localhost conf] vim httpd.conf   #修改主配置文件
#Listen 12.34.56.78:80
#Listen 80
Listen 192.168.9.254:8081     #修改
Listen 192.168.10.254:8082
[root@localhost conf]#apachectl stop     #重启
[root@localhost conf] apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

 

 

 基于不同域名(需要有域名解析:DNS服务)

[root@localhost conf] vim extra/httpd-vhosts.conf   #同样修改包含虚拟机主配置文件
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/apache/htdocs/skl1"
    ServerName www.skl.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/skl1-error_log"
    CustomLog "logs/skl1-access_log" common
</VirtualHost>

<VirtualHost *:80>     
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/local/apache/htdocs/skl2"
    ServerName dns.skl.com
    ErrorLog "logs/skl-error_log"


[root@localhost conf] vim httpd.conf   #修改主配置文件
Listen 80
#Listen 192.168.9.254:8081
#Listen 192.168.10.254:8082

[root@localhost conf] vim /etc/hosts
192.168.9.1   www.skl.com
192.168.10.1   dns.skl.com

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我还能再学点

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值