http服务

编译安装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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值