• web网站学习 apache (一)


    学习内容

    web 网站学习
    apache
    nginx
    tomcat

    apache概述

    Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。

    apache用户
    # tail -1 /etc/passwd
    apache进程
    # ps aux | grep httpd
    其中root运行的是主进程,apache运行的是子进程
    主进程的id保存在/etc/httpd/run/httpd.pid文件内
    真正来处理web请求的是子进程,主进程用来管理子进程
    apache模块
    # httpd -M
    apache是一个模块化设计的服务,核心只包含主要功能,扩展功能通过模块实现
    不同模块可以被金泰的编译进程序,也可以动态建在
    模块的动态加载通过DSO(Dynamic shared Object)实现
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    apache模式

    Apache一共有3种稳定的MPM模式(MPM:多进程处理模块),它们分别是 prefork、worker、event

    perfork 预派生,事先生成几个工作进程,每个进程对应一个线程
    特点:超级稳定,不支持高并发

    worker 工作模式,每个进程对应多个线程,支持高并发

    event 事件模式 每个进程对应多个线程,其中有一个线程专门用于监督其他线程,支持更高的并发

    配置文件详解

    1.主配置文件位置
    /etc/httpd/conf/httpd.conf
    检测配置是否有问题 
    # httpd -t
    修改后必须重启
    # systemctl restart httpd
    2.配置详解
    serverroot  服务所在目录的路径
    listen      监听端口
    include     导入配置文件
        include conf.modules.d/*.conf
    includeoption 导入辅助配置文件
                conf.d/*.conf
    ifmodule 以特定模块存在与否为条件的指令
    files     包含适用于匹配文件名的指令    拒绝访问
    errorlog  错误日志位置
    loglevel  错误日志级别
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    配置实战

    基于域名的虚拟主机
    一、基于域名的虚拟主机
    虚拟主机(重点)
    虚拟主机,也叫“网站空间”,就是把一台运行在互联网上的物理服务器划分成多个“虚拟”服务器。虚拟主机技术极大的促进了网络技术的应用和普及。同时虚拟主机的租用服务也成了网络时代的一种新型经济形式。
    虚拟主机的分类: 
    基于 IP 的虚拟主机:一台服务器,多个 ip,搭建多个网站 
    基于端口的虚拟主机:一台服务器,一个 ip,搭建多个网站,每个网络使用不同端口访问 
    root@hd1 conf.d]# cat /etc/httpd/conf/httpd.conf|grep -i  ^listen
    Listen 79
    Listen 81
    基于域名的虚拟主机:一台服务器,一个 ip,搭建多个网站,每个网站使用不同域名访问 
    Apache 实验
    启动服务,并设置开机启动
    [root@hd1 ~]# systemctl start httpd 
    [root@hd1 ~]# systemctl enable httpd 
    查看相应的端口是否起来了?
    [root@hd1 ~]# ss -naput |grep :80
    tcp    LISTEN     0      128      :::80   
    1. 域名解析:准备两个域名
    www.sohu.com 
    www.sina.com 
    #使用本地 hosts 文件进行解析
    # cat /etc/hosts
    127.0.0.1 localhost localhost.localdomai
    ::1       localhost localhost.localdomai
    192.168.1.11 www.hd1.com
    192.168.1.11 www.soudu.com
    192.168.1.11 www.sina.com
    2. 网站主页目录规划 
    在/var/www/html/目录下分别创建 sohu 和 sina 两个目录
    并在新建目录内创建 index.html 文件(分别创建不一样的内容
    [root@hd1 html]# cd sohu/
    [root@hd1 sohu]# echo sohu > index.html
    [root@hd1 html]# cd sina/
    [root@hd1 sohu]# echo sina > index.html
    修改主配置文件开启文件关联
    [root@hd1 conf]# vi httpd.conf
    IncludeOptional conf.d/*.conf  #查看此行是否被注释,需要打开
    编辑子配置文件,编写虚拟主机标签 
    [root@hd1 conf.d]# cat httpd-vhosts.conf 
    [root@hd1 conf.d]# cat vhosts.conf 
     
     	Options Indexes FollowSymLinks 
     	AllowOverride None 
     	Require all granted 
         
     
       ServerAdmin webmaster@sina.com 
       DocumentRoot "/var/www/html/sina"
       ServerName www.sina.com
        ErrorLog "logs/sina-error_log"
       CustomLog "logs/sina-access_log" common
    
     
     	Options Indexes FollowSymLinks 
     	AllowOverride None 
     	Require all granted 
         
      
       ServerAdmin webmaster@sohu.com
       DocumentRoot "/var/www/html/sohu"
       ServerName www.sohu.com
        ErrorLog "logs/sohu-error_log"
       CustomLog "logs/sohu-access_log" common
    
    重启服务,验证结果 
    [root@hd1 conf.d]# systemctl restart httpd 
    Windows 下:浏览器下输入两个不同的域名验证网页内容(提前修改 windows 的 hosts 文件)
    基于端口实现
    只需要修改
    vhosts.conf 中的下面两行
     
    
    修改配置文件中/etc/httpd/conf/httpd.conf
    Listen  79
    Listen  81
    测试curl 192.168.1.11:79
    测试curl 192.168.1.11:81
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77

    总结题

    跳转分配301永久跳转和302临时跳转
    # yum install -y httpd
    # httpd -V |grep Server   查看
    配置服务路径
    服务目录   /etc/httpd
    配置文件   /etc/httpd/conf/httpd.conf
    默认网站数据目录 /var/www/html
    访问日志   /var/log/httpd/access_log
    错误日志   /var/log/httpd/error_log
    1.apache的主配置文件
    /etc/httpd/conf/httpd.conf
    2.apache会自动生成几个进程
    跟cpu的核心数量有关系,一般是跟cpu的数量一致
    3.httpd在应用层
    4.重启网站服务
    systemctl restart httpd 
    在生产环境下,不可以随便使用这个命令
    6.虚拟主机有哪几种配置方式
    基于ip,基于域名,基于端口
    7.怎么查看httpd服务的访问日志路径
     ①使用rpm -ql httpd | grep log 
     ②到配置文件中查看配置路径
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
  • 相关阅读:
    第二十章《Java Swing》第5节:常用组件
    【ARM Coresight 系列文章19 -- Performance Monitoring Unit(性能监测单元)
    【C++/STL】stack和queue(容器适配器、优先队列、双端队列)
    JavaScript面向对象学习(一)
    web前端面试题附答案003-说一下你都用过那些格式的图片
    相控阵天线(十二):天线校准技术仿真介绍之旋转矢量法
    ubuntu环境搭建记录
    计算机毕业设计PySpark+大模型农产品推荐系统 农产品爬虫 农产品商城 农产品大数据 农产品数据分析可视化 PySpark Hadoop
    711气象雷达电路图
    【C】指针进阶(下)
  • 原文地址:https://blog.csdn.net/qq_48975137/article/details/132900614