竹子开花的时 发表于 2018-11-18 12:42:44

Apache web服务

  第九单元
  Apache web服务
  
  
  一 Apache安装
  1 yum install httpd -y                  ###安装apache软件包###
  2 systemctl start httpd               ###开启服务###
  3 systemctl enable httpd.service      ###开机自动开启服务###
  4 systemctl stop firewalld.service      ###关闭防火墙###
  5 systemctl disable firewalld.service   ###开机自动关闭###
  6 netstat -antlp   | grep httpd         ###查看监听端口###
  
  二 apache基本信息
  
  
  1 apache的默认发布目录
  
  index.html
  
  2 apache的配置文件
  
  /etc/httpd/conf/httpd.conf                ###主配置文件###
  
  ServerRoot "/etc/httpd"             ###用于指定Apache的运行目录###
  Listen 80                                    ###监听端口###
  User apache                         ###运行apache程序的用户和组###
  Group apache
  ServerAdmin root@localhost                   ###管理员邮箱###
  DocumentRoot "/var/www/html"             ###网页文件的存放目录###
      ##语句块自定义目录权限##
  Require all granted                     
  
  ErrorLog "logs/error_log"                ###错误日志存放位置###
  AddDefaultCharset UTF-8                  ###默认支持的语言###
  IncludeOptional conf.d/*.conf            ###加载其它配置文件###
  DirectoryIndex index.html                ###默认主页名称###
  
  
  /etc/httpd/conf.d/*.conf                  ###子配置文件###
  
  3 apache的默认发布目录
  
  /var/www/html
  
  4 apache的默认端口
  
  80
  
  三 apache的基本配置
  
  1 )默认文件的修改
  
  1 vim   /var/www/html/index.html         ###编写默认文件###
  内容:
  
   hello world
  
  2 vim   /var/www/html/ westos.html         ###编写默认文件###
  内容:
   westos linux
  
  
  3 vim   /etc/httpd/conf/httpd.con
  
  168
  169   DirectoryIndex westos.html index.html   ###默认westos.html为默认文件,如果westos.html不存在,则默认文件为index.html#####
  170
  
  4systemctl restart httpd.service      ###重新启动服务###
  
  
  测试:
  登入 172.25.254.112 查看显示的内容是index.html还是westos.html
  
  如果将westos.html文件删除
  
  
  过程如下:
  
  # cd /var/www/html/
  # ls
  admincgimysqladmin
  # vim index.html
  
  # vim westos.html
  # vim /etc/httpd/conf/httpd.conf
  
  # systemctl restart httpd.service
  # rm -fr westos.html
  
  2 )默认目录的修改
  当selinux是disabled的时候:
  
  1 mkdir /westos/www/test -p   ###建立一个目录作为默认目录###
  2 vim /westos/www/test/westos.html   ###编写默认文件###
  内容:
   westos's page
  
  3 vim /etc/httpd/conf/httpd.conf
  
  121 DocumentRoot "/westos/www/test"   ###修改默认目录###
  122
  123       ###设置默认目录访问权限####
  124   Require all granted            ####允许所有人访问####
  125
  
  4systemctl restart httpd.service    ###重启服务###
  
  测试:
  登入172.25.254.112查看内容:
  
  
  过程如下:
  # mkdir /westos/www/test -p
  # vim /westos/www/test/westos.html

  # vim /etc/httpd/conf/httpd.conf

  # systemctl restart httpd.service
  
  
  当selinux是enforcing状态:
  在添加下面两步:
  1 semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'###修改安全上下文###
  2 restorecon -RvvF /westos/    ###刷新###
  
  3 )apache的访问控制
  
  设定ip的访问:
  
  1 mkdir /var/www/html/admin/
  2 vim /var/www/html/admin/index.html
  
   admin's page
  
  3 vim /etc/httpd/conf/httpd.conf
  
              
        Order Allow,Deny               ###允许所有人访问admin目录但只有78主机不能访问###
        Allow from All
        Deny from 172.25.254.78
  
  
  
  
页: [1]
查看完整版本: Apache web服务