编译安装httpd-2.4
实验环境
主机名 | 类型 | IP |
---|---|---|
[root@server ~] | 服务端 | 192.168.102.128 |
- 关闭防火墙
- 关闭selinux
安装开发环境
[root@server ~]# yum groupinstall "Development Tools"
[root@server ~]# useradd -r -g apache apache #创建apache用户并将其加入apache组中
[root@server ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
下载并解压apr-1.6.3和apr-util-1.6.1
[root@server ~]# cd /usr/src/
[root@server src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.
tar.bz2
[root@server src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1
.6.1.tar.bz2
[root@server src]# tar xf apr-1.6.3.tar.bz2
[root@server src]# tar xf apr-util-1.6.1.tar.bz2
[root@server src]# ls
apr-1.6.3 apr-1.6.3.tar.bz2 apr-util-1.6.1 apr-util-1.6.1.tar.bz2 debug kernels
[root@server src]# cd apr-1.6.3
[root@server apr-1.6.3]# vim configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" #删除此行,或者加上注释
编译安装
[root@server apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@server apr-1.6.3]# make && make install
[root@server apr-1.6.3]# cd /usr/src/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-2.4
[root@server ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.3
4.tar.bz2
[root@server ~]# ls
httpd-2.4.34.tar.bz2
[root@server ~]# tar xf httpd-2.4.34.tar.bz2
[root@server ~]# cd httpd-2.4.34
[root@server httpd-2.4.34]# ./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@server httpd-2.4.34]# make && make install
[root@server httpd-2.4.34]cd /usr/local/apache/bin
[root@server bin]# ./apachectl start
查询正在运行的httpd服务进程
[root@server ~]# ps -ef |grep httpd
root 40225 1 0 10:47 ? 00:00:01 /usr/local/apache/bin/httpd -k start
root 40446 6276 0 10:57 pts/2 00:00:00 vim /etc/httpd24/httpd.conf
daemon 40766 40225 0 11:17 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 40767 40225 0 11:17 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 40768 40225 0 11:17 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 40769 40225 0 11:17 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 40770 40225 0 11:17 ? 00:00:00 /usr/local/apache/bin/httpd -k start
daemon 40825 40225 0 11:23 ? 00:00:00 /usr/local/apache/bin/httpd -k start
root 43027 6276 0 15:18 pts/2 00:00:00 grep --color=auto httpd
在Windows上面验证(用谷歌或者火狐)
配置三种类型虚拟机
1、相同IP不同端口
[root@server htdocs]# pwd
/usr/local/apache/htdocs
[root@server htdocs]# mkdir ow
[root@server htdocs]# mkdir wf
[root@server htdocs]# touch mm.log
[root@server htdocs]# echo 'hello' > ow/index.html
[root@server htdocs]# echo 'hello world' > wf/index.html
[root@server htdocs]# ls
mm.log index.html ow wf
更改配置文件
[root@httpd ~]# vim /etc/httpd24/httpd.conf
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
ServerAdmin root@server #设置管理员邮箱
-------------
# If your host doesn't have a registered DNS name, enter its IP addres s here.
#
ServerName www.example.com:80 #取消前面的#号
# Deny access to the entirety of your server's filesystem. You must
-----------------
#Listen 12.34.56.78:80
Listen 80
Listen 8080 #添加监听8080端口
-----------------
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin #在配置文件下增加如下内容
</IfModule>
<VirtualHost 192.168.102.128:80> #虚拟主机1
ServerName www.ddkddkddk.com
DocumentRoot "/usr/local/apache/htdocs/ow"
ErrorLog "/usr/local/apache/htdocs/mm.log"
CustomLog "/usr/local/apache/htdocs/mm.log" combined
<Directory /usr/local/apache/htdocs/ow>
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.102.128:8080> #虚拟主机2,端口为8080
ServerName www.wf.com
DocumentRoot "/usr/local/apache/htdocs/wf"
ErrorLog "/usr/local/apache/htdocs/mm.log"
CustomLog "/usr/local/apache/htdocs/mm.log" combined
<Directory /usr/local/apache/htdocs/wf>
Require all granted
</Directory>
</VirtualHost>
--------------------
重启
[root@server bin]# ./apachectl restart
[root@server bin]# pwd
/usr/local/apache/bin
Windows验证
2、相同端口不同IP
[root@server ~]# ip addr add 192.168.102.129/24 dev ens33 #增加ip
[root@server ~]# ip a #查看ip
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:df:b0:34 brd ff:ff:ff:ff:ff:ff
inet 192.168.102.128/24 brd 192.168.118.255 scope global ens33
valid_lft forever preferred_lft forever
inet 192.168.102.129/24 scope global secondary ens33
valid_lft forever preferred_lft forever
改配置
[root@server ~]# vim /etc/httpd24/httpd.conf
##
# but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin #在配置文件末尾增加如下内容
</IfModule>
<VirtualHost 192.168.102.128:80> #虚拟主机1
ServerName www.ddkddkddk.com
DocumentRoot "/usr/local/apache/htdocs/ow"
ErrorLog "/usr/local/apache/htdocs/mm.log"
CustomLog "/usr/local/apache/htdocs/mm.log" combined
<Directory /usr/local/apache/htdocs/ow>
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.102.129:80> #虚拟主机2 ip为192.168.102.129
ServerName www.dxkdxkdxk.com
DocumentRoot "/usr/local/apache/htdocs/wf"
ErrorLog "/usr/local/apache/htdocs/mm.log"
CustomLog "/usr/local/apache/htdocs/mm.log" combined
<Directory /usr/local/apache/htdocs/wf>
Require all granted
</Directory>
</VirtualHost>
------------------
[root@server bin]# ./apachectl restart
[root@server bin]# pwd
/usr/local/apache/bin
Windows验证
2、相同IP相同端口不同域名
更改配置
[root@httpd ~]# vim /etc/httpd24/httpd.conf
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin #在配置文件下增加如下内容
</IfModule>
<VirtualHost 192.168.102.128:80> #虚拟主机1与虚拟主机二ip和端口号相同
ServerName www.ddkddkddk.com #虚拟主机1访问域名
DocumentRoot "/usr/local/apache/htdocs/ow"
ErrorLog "/usr/local/apache/htdocs/mm.log"
CustomLog "/usr/local/apache/htdocs/mm.log" combined
<Directory /usr/local/apache/htdocs/ow>
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.102.128:80>
ServerName www.dxkdxkdxk.com #虚拟主机二访问域名
DocumentRoot "/usr/local/apache/htdocs/wf"
ErrorLog "/usr/local/apache/htdocs/mm.log"
CustomLog "/usr/local/apache/htdocs/mm.log" combined
<Directory /usr/local/apache/htdocs/wf>
Require all granted
</Directory>
</VirtualHost>
windows
重启
[root@server bin]# ./apachectl restart
[root@server bin]# pwd
/usr/local/apache/bin
windows验证
nice!成功!