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

apache服务的管理

apache服务的管理

apache服务的管理

apache服务的管理

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

apache服务的管理

apache服务的管理


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/

apache服务的管理

apache服务的管理

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)则发布自己所建立的

apache服务的管理

apache服务的管理

apache服务的管理

apache服务的管理


apache服务的管理

6. 修改默认发布目录

     vim /etc/httpd/conf/httpd.conf

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

apache服务的管理

apache服务的管理

apache服务的管理

apache服务的管理

apache服务的管理

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

           <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>

apache服务的管理


测试:linux.com  http://172.25.254.190

apache服务的管理

apache服务的管理

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

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

            vim /etc/hosts

            172.25.254.190   linux.com

apache服务的管理


8. 用户方式的访问控制

    htpasswd -cm /etc/httpd/userpass  wzw

    htpasswd -m  /etc/httpd/userpass   wzw1

apache服务的管理

apache服务的管理

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

apache服务的管理


9. apache支持的语言

  a.html

  b.php

     yum install php -y

     vim /var/www/html/index.php

     <?php

                 phpinfo();

      ?>

      systemctl restart httpd

apache服务的管理

测试:172.25.254.190/index.php

apache服务的管理

  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>

apache服务的管理

apache服务的管理

apache服务的管理

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

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

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

apache服务的管理

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

apache服务的管理

apache服务的管理

apache服务的管理

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

apache服务的管理

测试https : 需要下载证书

apache服务的管理


  <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>

apache服务的管理

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

apache服务的管理

   <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)永久的转换

apache服务的管理







  

  


  







相关文章:

  • 2021-12-22
  • 2021-05-14
  • 2021-06-04
  • 2021-07-06
  • 2021-06-20
  • 2022-01-13
  • 2021-06-21
  • 2022-12-23
猜你喜欢
  • 2021-09-15
  • 2021-06-25
  • 2022-01-22
  • 2021-07-30
  • 2021-04-20
  • 2021-11-28
相关资源
相似解决方案