httpd-2.4.6



1.基础html


安装:web

[root@tri manual]# yum install httpd-manual httpd


源码编译shell

configure配置选项
配置选项
默认值
备注
-prefix

服务器的根路径
--with-mpm
event
event/worker/prefork/winnt
-enable-ssl



主程序/httpd:数据库

httpd命令选项
选项
备注
-f /etc/httpd/conf/httpd.conf 指定配置文件
-v
查看版本
-l
编译到服务器的模块(不包括动态加载)
-M
查看静态、共享模块
-S
查看当前配置文件设置
-t
检查配置文件语法
-V
httpd编译参数




配置指令:
apache

httpd.conf
配置指令
备注
ServerRoot "/etc/httpd" 服务器的根路径
TimeOut 120
TCP握手超时
KeepAlive off
HTTP持久链接
KeepAliveTimeout 5
持久链接超时(5秒)
MaxKeepAliveRequests 100
持久连接容许的请求数
ServerName www.tripartite.tech:8080
服务器主机名
DocumentRoot htdocs/
默认请求目录
options Indexes FollowSymLinks

列出目录、服务器接受符号连接浏览器

none:啥都不设置安全

Includes:服务器端包含bash

DirectoryIndex

AllowOverride

Order allow,deny

访问控制服务器

Allow,Deny网络

  任何符合Allow将放行,任何符合Deny将拒绝;均不符合,将拒绝。

Deny,Allow

  若是匹配Deny,请求拒绝,除非它也匹配Allow指令;均不符合,将放行。

Allow from all
访问控制(网络地址、ip地址、域名、域)
Deny from all


例子:

# 拒绝某个ip访问
Order Allow,Deny
Allow from all
Deny from 115.120.85.152


2.用户指南


2.1.配置文件

  Apahce HTTP服务的配置文件,是由一系列指令构成的纯文本文件。主配置文件一般叫作“httpd.conf”,路径在编译时指定,可是启动服务时能够被选项“-f”覆盖。还可使用“Include”指令,加载其余配置文件。任何指令,能够出如今配置文件的任何位置。配置文件修改后,只有在其后启动服务才能生效。

  每一个指令单独占用配置文件的一行,使用反斜线“\”能够把过长的一行配置拓展到下一行。拓展时,在反斜线后边不能存在空白字符。指令的参数由空白字符分割,参数自身含有空白字符时,须要用到双引号。配置文件中的指令不区分大小写,可是指令的参数是大小写敏感的。指令前的空白符是被忽略的,全部为了方便查看,能够进行缩进。

  配置文件接受变量的定义(Define),获取变量的值时跟shell脚本中同样($var)。使用Define定义的变量,会覆盖shell的环境变量。

  在不启动服务的状况下,能够经过命令判断配置文件语法的正确性。能够经过“f”选项在当前服务的配置文件外配置好配置文件并检验好后,在覆盖默认配置文件。

[root@Rsync httpd2.2.8]# bin/httpd -t
Syntax OK
[root@Rsync httpd2.2.8]# bin/httpd -t -f /home/work/httpd.conf
Syntax OK


2.1.1.模块编译

模块属性
说明
MPM

多处理模块

有且只能有一个该类模块。响应客户端的请求处理、调度。默认会自动编译,rpm包中经常是动态加载的,而源码包安装时默认是静态加载的。

Base
默认被编译
Extension
默认不会被编译,须要使用到该类模块时,经常须要从新编译。
Experimental
工具套件用到的模块,表示当前版本再也不支持。
External
第三方提供的模块,须要时应从新编译。


  httpd是一个模块化的服务。httpd的核心服务只包含最基本的功能,扩展功能须要更多的模块来实现。当须要使用某个特殊的功能时,可能须要从新编译源代码来使用。不一样的模块大体分为几类:MPM、Base、Extension、Experimental、External。

  若是httpd服务被编译为使用动态加载模块,则可使用指令“LoadModule”在任什么时候候单独加载(随后编译的)模块。查看当前httpd服务编译了哪些模块,可使用选项“l”。查看哪些模块被动态加载,可使用选项“M”。

[root@Rsync httpd2.2.8]# bin/httpd -M
Loaded Modules:
 core_module (static)
...
[root@Rsync httpd2.2.8]# bin/httpd -l
Compiled in modules:
  core.c
...


  更多关于编译的信息,……(关于当前编译信息、能够用到的配合指令)

# 编译时的配置信息:
[root@Rsync httpd2.2.8]# bin/httpd -V
Server version: Apache/2.2.8 (Unix)
Server built:   Aug 18 2017 09:59:05
Server's Module Magic Number: 20051115:11
Server loaded:  APR 1.2.12, APR-Util 1.2.12
Compiled using: APR 1.2.12, APR-Util 1.2.12
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"

# 查看编译后可使用到配置指令。
[root@Rsync httpd2.2.8]# bin/httpd -L
<Directory (core.c)
    Container for directives affecting resources located in the specified directories
    Allowed in *.conf only outside <Directory>, <Files> or <Location>
<Location (core.c)
    Container for directives affecting resources accessed through the specified URL paths
    Allowed in *.conf only outside <Directory>, <Files> or <Location>
<VirtualHost (core.c)
    Container to map directives to a particular virtual host, takes one or more host addresses
    Allowed in *.conf only outside <Directory>, <Files> or <Location>


2.1.2.指令范围

  指令位于主配置文件,将做用于整个服务。当须要缩小指令的范围时,能够将其嵌入“Directory”、“DirectoryMatch”、“Files”、“FilesMatch”、“Location”、“LocationMatch”这些“配置块中。这些指令容许嵌套,实现更加精细的管理。

  httpd能够同时发布多个不一样站点,这个功能常被称为“虚拟主机”。其中的指令将限制做用在<VirtualHost>配置块中,用来响应某个特定的站点。

  尽管大部分指令能够位于配置文件的任意位置,可是,关于控制进程建立的指令仅能出如今主配置上下文中。


2.1.3.分布式配置文件

  容许出如今目录的任意子目录中,用来针对目录进行分散管理。其语法与主配置文件相同。因为每一个请求接收的时候都会读取该配置文件(.htaccess),因此在这些文件中所作的更改当即生效(无须重启服务)。

  默认文件名为“.htaccess”,能够经过指令“AccessFileName”从新指定。

[root@tri httpd-2.4.6]# bin/httpd -L  | grep -A 2  "^Access"
AccessFileName (core.c)
    Name(s) of per-directory config files (default: .htaccess)
    Allowed in *.conf only outside <Directory>, <Files>, <Location>, or <If>


  因为是个分布式配置,可能会与主配置文件在某些时候相左,这时另一个指令“AllowOverride”就粉墨登场了。


2.2.绑定地址、端口

  httpd启动的时候,默认监听全部的本地地址。可是须要指定监听某个肯定的端口,或者地址,端口和地址(用在设置虚拟机的时候)。Listen指令设定服务接收请求在某个地址、端口。

  同时监听多个端口

Listen 80
Listen 8000

  监听不一样的地址

Listen 192.0.2.1:80
Listen 192.0.2.5:8000

  监听IPv6地址,须要用到一对中括号。

Listen [::]:80


  Listen指令还有另一个选项,用来指定监听的协议

Listen 192.170.2.1:8443 https


2.3.配置块(块容器)

  配置文件中的指令,能够做用于整个服务。也能够用来限定某个特定的目录、文件、主机、URL。配置块又叫作块容器。


2.3.1.配置块种类

  大体分为两类,仅仅在服务器启动时产生效果的块容器(封闭容器),和每次都会响应请求的块容器(开放块容器)。像以‘If’开头的系列,<IfDefine>,<IfModule>,<IfVersion>若是符合特定条件就一次性响应。

[root@tri httpd-2.4.6]# bin/httpd -L  | grep -A 3  "^<If"
<IfModule (core.c)
    Container for directives based on existence of specified modules
    Allowed in *.conf anywhere and in .htaccess
    when AllowOverride isn't None
<IfDefine (core.c)
    Container for directives based on existence of command line defines
    Allowed in *.conf anywhere and in .htaccess
    when AllowOverride isn't None
--
<If (core.c)
    Container for directives to be conditionally applied
    Allowed in *.conf anywhere and in .htaccess
    when AllowOverride isn't None
--
<IfVersion (mod_version.c)
    a comparison operator, a version (and a delimiter)
    Allowed in *.conf anywhere [no per-dir config] and in .htaccess
    when AllowOverride isn't None


2.3.2.开放块容器

  我没有在apache httpd的说明文档中找到这个说法,“开发块容器”仅仅是个人我的理解。不在你们的讨论之列,你有好的建议我以为能够接受,能够修改个人标题。


  开发块大多用在配置文件系统(文件块,httpd占用到的空间),网页空间(网页块,发布出去的空间,也可能包含一些数据库中的内容)。

  文件块的表明,<Directory>、<Files>,其中指令做用于该目录、子目录、以及其中的文件。(实现同样的效果,也可使用“分布式配置文件”)

<Directory /var/web/dir1>
    Options +Indexes
</Directory>
<Directory /var/web/dir1>
    <Files private.html>
        Require all denied
    </Files>
</Directory>


  网页块的表明,<Location>、<LocationMatch>……

<LocationMatch ^/private>
    Require all denied
</LocationMatch>
<Location /server-status>
    SetHandler server-status
</Location>


2.4.服务配置

  core提供的一些基本配置指令

2.4.1.服务识别

  ①ServerName

    服务标识符,重定向时须要用到。用于虚拟主机时,会覆盖主配置的设置项目。

ServerName www.example.com
当设置中没有出现端口号时,会自动对应请求进来时使用的端口号


  ②ServerAdmin

    当访问出现错误时,返回给客户浏览器联系信息。

ServerAdmin www-admin@example.com


  ③ServerSignature

    用于在返回的页面下产生一行内容(httpd版本、服务器域名、端口),调试未知页面错误时较为有用。

ServerSignature On|Off|EMail
默认Off

效果:wKioL1mn8PLyLZ-PAAAUJew9CHo469.png


  ④ServerTokens

    用于返回错误时提供某些服务器的信息。


2.4.2.文件位置

  ①DocumentRoot

    httpd发布文件的根目录

  ②ErrorLog

    设定日志文件的名称(包含路径),不是绝对路径的时候,以ServerRoot为基础。默认“logs/error_log”(unix)。

  PifFile

    默认“logs/httpd.pid”

  ServerRoot

    服务安装的路径,路径在编译经过“prefix”肯定。


2.5.SSL/TLS

  httpd使用了模块“mod_ssl”,该模块提供了OpenSSL库的接口。使httpd实现安全套接字层和传输层安全协议的强加密成为可能。


2.5.1.mod_ssl配置

相关文章
相关标签/搜索