apache服务的管理

1. apache的定义: 企业中常用的web服务,用来提供http:// (超文本传输协议)

2. apache的安装部署

    yum  install  httpd -y

    yum  install  httpd-manual -y

    systemctl  start httpd

    systemctl  enable httpd 

    systemctl  stop  firewalld

    systemctl disable firewalld

部署完后,可以在另一台主机进行测试:http://172.25.254.190    http://172.25.254.190/manual


3. apache的基础文件信息

    /etc/httpd/conf                                          ##主配置目录

    /etc/httpd/conf/httpd.conf                         ##主配置文件

    /etc/httpd/conf.d                                       ##子配置目录

    /etc/httpd/conf.d/*.conf                             ##子配置文件

    /var/www/html                                          ##默认发布目录

    index.html                                                ##默认发布文件

    80  (ss -antlupe | grep httpd )                    ##查询默认端口号为80

    httpd_sys_content_t                                ##默认安全上下文

    /etc/httpd/logs/*                                       ##apache的日志

注意:若httpd服务连接失败,用 ls  -Z  来查看安全上下文是否有问题,若有则用下列命令来添加安全上下文

            semanage  fcontext  -a  -t  httpd_sys_content_t  '/www(/.*)?'

            restorecon    -RvvF  /www/

4. 修改默认端口

    vim /etc/httpd/conf/httpd.conf                   ##在主配置文件中做修改

*   Listen  8080                                             ##修改默认端口号为8080

 测试:http://172.25.254.190:8080

5. 修改默认发布文件

    vim /etc/httpd/conf/httpd.conf

*   DirectoryIndex  index.html  *.html            ##按顺序发布,若没有默认的发布文件(index.html)则发布自己所建立的


6. 修改默认发布目录

     vim /etc/httpd/conf/httpd.conf

*    DocumentRoot  "/mnt/html"                  ##修改默认发布目录为"/mnt/html/"

注意:自己修改过的默认发布目录都需要对目录进行授权

           <Directory "/www">

                 Require  all  granted

           </Directory>

          以上语句的授权方式是允许所有,也可以用下面语句来进行指定的授权      

               <Directory "/www">

                   Order deny,allow                   ##按顺序读取,后面读取的会覆盖前面重复的

                   Deny  from  all 

                    Allow  from 172.25.254.190

           </Directory>

          只允许172.25.254.190主机进行超文本的传输

7. apache的虚拟主机(进行多个站点的发布)

    vim /etc/httpd/conf.d/Linux.conf            ##默认子配置文件

    <VirtualHost  *:80>

                ServerName      linux.wzw.com

                DocumentRoot  "/var/www/virtual/linux.wzw.com/html"    ##默认的发布目录

                CustomLog        "logs/*.log"  combined  ##将日志保存到/etc/httpd/logs/*.log中(combined)四种日志综合

    </VirtualHost>

    <Directory "/var/www/virtual/linux.wzw.com/html">

                 Require  all  granted

    </Directory>

   

    vim /etc/httpd/conf.d/default.conf            ##默认子配置文件

    <VirtualHost  _default_:80>

                DocumentRoot  "/var/www/html"    ##默认的发布目录

                CustomLog        "logs/*.log"  combined  ##将日志保存到/etc/httpd/logs/*.log中(combined)四种日志综合

    </VirtualHost>


测试:linux.com  http://172.25.254.190

注意:在修改默认发布目录之前一定要记得先建立好新的发布目录,在发布目录下写好测试的发布文件

           在所测试的主机里要做好本地解析:

            vim /etc/hosts

            172.25.254.190   linux.com


8. 用户方式的访问控制

    htpasswd -cm /etc/httpd/userpass  wzw

    htpasswd -m  /etc/httpd/userpass   wzw1


设置只允许wzw访问,用户输入wzw1时不能访问



9. apache支持的语言

  a.html

  b.php

     yum install php -y

     vim /var/www/html/index.php

     <?php

                 phpinfo();

      ?>

      systemctl restart httpd


测试:172.25.254.190/index.php


  c.cgi

     vim /var/www/html/cgi/index.cgi

     #!/usr/bin/perl

     print "Content-type: text/html\n\n";

     print `date`;

     chmod +x /var/www/html/cgi/index.cgi

      /var/www/html/cgi/index.cgi                        ##执行脚本先确定脚本的运行正常

     vim default.conf

     <Directory "/var/www/html/cgi">

              Options  +ExecCGI

              AddHandler cgi-script .cgi

     </Directory>



10. 设定https虚拟主机并设定网页的重写

目的:让默认的http自动跳转到加密的https文本传输中

a. https的默认端口号为443,所以先需要安装


b. 生成安全证书   genkey 公司名称




在/etc/httpd/conf.d/ssl.conf中加入自己生成的钥匙和认证


测试https : 需要下载证书



  <VirtualHost  *:443>

                ServerName      login.wzw.com

                DocumentRoot  "/var/www/virtual/login.wzw.com/html"    ##默认的发布目录

                CustomLog        "logs/*.log"  combined  ##将日志保存到/etc/httpd/logs/*.log中(combined)四种日志综合

                SSLEngine  on

                SSLCertificateFile  /etc/pki/tls/certs/www.wzw.com.crt             ##证书的锁

                SSLCertificateFile  /etc/pki/tls/private/www.wzw.com.key        ##证书的钥匙    

   </VirtualHost>

   <Directory "/var/www/virtual/login.wzw.com/html">

                 Require  all  granted

   </Directory>

先进行https的测试,若无问题则加上让443端口跳转为80端口类型的语句


   <VirtualHost *:80>

               ServerName  login.wzw.com

               RewriteEngine  on

               RewriteRule  ^(/.*)$ https://%(HTTP_HOST)$1   [redirect=301]

   </VirtualHost>

测试:login.wzw.com

    ^(/.*)$                                          ##客户在浏览器地址栏中输入的所有字符

   https://                                         ##强制客户加密访问

   %{HTTP_HOST}                        ##客户请求主机

   $1                                                ##表示^(/.*)$的值

   [redirect=301]                              ##临时重写 (302)永久的转换








  

  


  







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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值