当前位置:   article > 正文

CentOS7 yum安装 Apache2.4_centos 安装apachebench2.4.*

centos 安装apachebench2.4.*

安装Apache

  • 安装
yum install httpd -y
rpm -qa httpd
  • 1

启动测试Apache

  1. 启动
systemctl start httpd.service
    1. 查看是否启动成功
    systemctl rehttpd.service
      1. 在Linux端测试
        添加hosts解析
      [root@localhost ~] echo "192.168.137.137 www.dduan.com">>/etc/hosts
      [root@localhost ~] tail -1 /etc/hosts
      192.168.137.137 www.dduan.com
      • 1
      • 2
      1. 使用curl命令测试
      [root@localhost ~]# echo "http://www.$HOSTNAME">/var/www/html/index.html
      [root@localhost ~]# cat /var/www/html/index.html 
      http://www.dduan.com
      [root@localhost ~]# curl http://www.dduan.com
      http://www.http://www.dduan.com.com
      • 1
      • 2
      • 3
      • 4

      配置Apache

      1. 修改前备份文件
      [root@localhost ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.$(date +%F)
      [root@localhost ~]# ll /etc/httpd/conf/httpd.conf
      -rw-r--r-- 1 root root 11753 Nov 15 00:53 /etc/httpd/conf/httpd.conf
      -rw-r--r-- 1 root root 11753 Jan 10 18:42 /etc/httpd/conf/httpd.conf.2018-12-05
      • 1
      • 2
      • 3
      1. 配置httpd文件
        因为在apache2.4中变化挺大,和nginx一样,可以自定义.conf文件。
        在主配置文件中启用虚拟主机
      [root@localhost httpd]# mkdir /etc/httpd/vhost.d/
      [root@localhost httpd]# echo "include vhost.d/*.conf"
      [root@localhost httpd]# tail -1 /etc/httpd/conf/httpd.conf
      include vhost.d/*.conf
      • 1
      • 2
      • 3
      1. 虚拟主机配置文件
      <VirtualHost *:80>
          ServerAdmin admin@amsilence.com
          DocumentRoot "/var/www/html/"
          ServerName blog.dduan.com
          ErrorLog "/var/log/httpd/logs/error_log"
          CustomLog "/var/log/httpd/logs/access_log" common
      </VirtualHost>
      
      <Directory /var/www/html/>
      Require all granted
      </Directory>
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      1. 测试配置文件是否正确
      [root@localhost httpd]# /sbin/service httpd configtest
      Syntax OK
      
      • 1
      • 2
      1. 重新启动apache服务
      systemctl rehttpd.service

        测试web服务

        1. curl测试
        [root@localhost html]# curl www.dduan.com
        www.dduan.com
        
        • 1
        • 2
        1. 浏览器测试
          在这里插入图片描述
        声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/669137
        推荐阅读
        相关标签
          

        闽ICP备14008679号