httpd 2.4

5 篇文章 0 订阅
1 篇文章 0 订阅

1.简介

安装:yum install -y httpd

主程序:/usr/sbin/httpd   

            httpd2.4支持MPM的动态切换

配置文件:/etc/httpd/conf   /etc/httpd/conf.d/*.conf

模块相关的配置文件:/etc/httpd/conf.modules.d/*.conf

模块文件路径:/usr/lib64/httpd/modules

systemd unit file:      /usr/lib/systemd/system/httpd.service

访问日志,错误日志,默认目录:/var/log/httpd  (access_log error_log)

网页文件目录:/var/www

网页文件默认目录:/var/www/html

例如:

   https://mp.csdn.net/index.html

   scheme://server[:port][/PATH/TO/SOME_SOURCE]

   httpd默认 DocumentRoot:  /var/www/html

服务控制:

   systemctl start httpd.service

  systemctl stop httpd.service

  systemctl restart httpd.service

 

2. httpd特性

CGI:Common Gateway Interface

虚拟主机: IP  PORT  FQDN

反向代理

负载均衡

路径别名

丰富的用户认证机制

支持第三方模块

...

3.常用配置项

/etc/httpd/conf/httpd.conf

格式: 指令   值

其中,指令不区分大小写,值则有可能区分大小写

通常以新增配置文件的方式修改httpd配置项,解耦,灵活

 

0.配置文件中的配置块:

<Directory />
    AllowOverride none
    Require all denied
</Directory>

1.监听端口

Listen [IP-address:]portnumber [protocol]     ---地址可省略,端口不能省略

例如:Listen 80

2.长连接

KeepAlive On|Off                            ------ Enables HTTP persistent connections
KeepAliveTimeout num[ms]            ------ Amount of time the server will wait for subsequent requests on a persistent connection
MaxKeepAliveRequests number     ------ Number of requests allowed on a persistent connection

3.MPM

httpd -M                   ----列出所有模块

在以下文件中配置:/etc/httpd/conf.modules.d/00-mpm.conf

mpm_prefork.conf文件内容如下:

<IfModule mpm_prefork_module>
    StartServers                       10         # 启动时进程数
    MinSpareServers                5          # 最小空闲进程数
    MaxSpareServers               10         # 最大空闲进程数
    MaxRequestWorkers          100        # 最大并发进程数
    MaxConnectionsPerChild   10000  # 最大连接数限制
</IfModule>

PV(page view):  一次完整的页面访问,包括该页面的所有资源

UV(user view):   独立的用户浏览量

IP:                           IP访问量

4.DSO  (Dynamically Shared Objects)

所有使用 httpd -M 显示为 (shared) 的模块都可以使用 LoadModule 装载

 

5.定义Main Server的文档页面路径

ServerName [scheme://]domain-name|ip-address[:port]

ServerAlias

DocumentRoot  directory-path  ---- 指定 URL PATH 与 File System PATH 的映射关系

 

6.站点访问控制

可基于两种机制对资源进行访问控制

文件系统路径:

<Directory "">
</Directory>

<File "">
</File>

<FileMatch "PATTERN">
</FileMatch>

URL路径:

<Location  "">
</Location>


<LocationMatch  "PATTERN">
</LocationMatch>

基于源地址的访问控制:

Require all granted

Require all deneid

基于IP控制:

 Require ip 10 172.20 192.168.2

 Require not ip 10 172.20 192.168.2

基于host控制:

    Require host HOST_NAME

 Require not host HOST_NAME

要放置在<RequireAll> 或 <RequireAny> 配置块中

Options:

Indexes

If a URL which maps to a directory is requested, and there is no DirectoryIndex (e.g., index.html) in that directory, then mod_autoindex will return a formatted listing of the directory.

如果该目录没有index.html,则可以列出该目录下所有资源文件

FollowSymLinks

The server will follow symbolic links in this directory. This is the default setting.

Even though the server follows the symlink it does not change the pathname used to match against <Directory> sections.

The FollowSymLinks and SymLinksIfOwnerMatch Options work only in <Directory> sections or .htaccess files.

Omitting this option should not be considered a security restriction, since symlink testing is subject to race conditions that make it circumventable.

如果使用该选项,则可以访问连接文件 连接至 其他目录或文件

7.定义站点主页面

DirectoryIndex index.html

8.定义路径别名

 Alias /webpath /full/filesystem/path

即 将 /webpath 这个URL重定向至 文件系统的/full/filesystem/path

注意:别名的路径 /full/filesystem/path 也需要显式授权 (Require all granted)

9.设定默认字符集

AddDefaultCharset UTF-8

10.日志设定

ErrorLog "logs/error_log"

CustomLog "logs/access_log" combined   

     ----相对于ServerRoot的路径 ( ServerRoot "/etc/httpd"),而该目录的logs是个软链接:

[root@localhost ~]# ll /etc/httpd/logs
lrwxrwxrwx. 1 root root 19 Dec 21 21:59 /etc/httpd/logs -> ../../var/log/httpd

    所以http的log都放在/var/log/httpd下

    log的格式由 LogFormat 定义

Common Log Format (CLF)

"%h %l %u %t \"%r\" %>s %b"

Common Log Format with Virtual Host

"%v %h %l %u %t \"%r\" %>s %b"

NCSA extended/combined log format

"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""

    各种字符的定义:http://httpd.apache.org/docs/2.4/mod/mod_log_config.html

11.基于用户的访问控制

认证质询:

      www-authenticate:响应码401,拒绝客户端请求,要求账号密码

认证:

     Authorization:客户端输入账号密码后再次发送请求报文,认证通过后,服务器发送响应资源

认证有两种:

    basic:明文

    digest:消息摘要认证

配置示例:

<Directory "/data/www">
  Options None
  AllowOverride None
  AuthType basic
  AuthName "Hello Please Auth"
  AuthUserFile "/etc/httpd/conf.d/myAuth.users"
  Require user hss tom
  #Require valid-user
  #AuthGroupFile "/path/to/groupfile"
  #Require group groupname
</Directory>

认证文件可使用htpasswd

htpasswd  [options]  /path/to/authfile   username

    -c 第一次创建文件时使用,如果文件已存在,则会覆盖

    -m  md5格式加密

    -s  sha格式加密

    -D 删除指定用户

    -b 批量添加用户    htpasswd  -b  [options]  /path/to/authfile   username  password

12.虚拟主机

基于IP:           ----  为每个主机提供至少一个IP

基于PORT:    ----  为每个主机提供至少一个PORT

基于FQDN:    ----  为每个主机提供至少一个FQDN,根据请求报文中的host字段路由到不同的虚拟主机

  配置示例:

<VirtualHost 192.168.75.10:80>   #地址可以写成*:80
  ServerName www.a.com
  DocumentRoot "/data/www/a_com"
  <Directory "/data/www/a_com">
      Options None
      AllowOverride None
      Require all granted
  </Directory>
</VirtualHost>

<VirtualHost 192.168.75.10:80>
  ServerName www.b.com
  DocumentRoot "/data/www/b_com"
  <Directory "/data/www/b_com">
      Options None
      AllowOverride None
      Require all granted
  </Directory>
</VirtualHost>

  13.status页面

  配置示例:

<Location /url/path/to/status>
  SetHandler server-status
  Require all granted        #注意,此处可做认证
</Location>

URL:

        基本语法:
            <scheme>://[<user>[:<password>]@]<host>:<port>/<path>[;<params>][?<query>][#<frag>]
                params: 参数
                    http://www.baidu.com/bbs/hello;gender=f
                query:
                    http://www.baidu.com/bbs/item.php?username=tom&title=abc
                frag:
                    https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html-single/Installation_Guide/index.html#ch-Boot-x86

14.curl命令

            curl  [options]  [URL...]

            curl的常用选项:

                -A/--user-agent <string> 设置用户代理发送给服务器
                -e/--referer <URL> 来源网址
                --compressed 要求返回是压缩的格式
                -I/--head 只显示响应报文首部信息
                --basic 使用HTTP基本认证
                --tcp-nodelay 使用TCP_NODELAY选项
                --cacert <file> CA证书 (SSL)
                -H/--header <line>自定义首部信息传递给服务器
                --limit-rate <rate> 设置传输速度
                -u/--user <user[:password]>设置服务器的用户和密码
                -0/--http1.0 使用HTTP 1.0  

15.user/group

            指定以哪个用户的身份运行httpd服务进程;
                User apache
                Group apache

16、使用mod_deflate模块压缩页面优化传输速度

       该操作节约带宽,但是消耗更多CPU

            SetOutputFilter DEFLATE

            # mod_deflate configuration
            # Restrict compression to these MIME types
            AddOutputFilterByType DEFLATE text/plain
            AddOutputFilterByType DEFLATE text/html
            AddOutputFilterByType DEFLATE application/xhtml+xml
            AddOutputFilterByType DEFLATE text/xml
            AddOutputFilterByType DEFLATE application/xml
            AddOutputFilterByType DEFLATE application/x-javascript
            AddOutputFilterByType DEFLATE text/javascript
            AddOutputFilterByType DEFLATE text/css

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
httpd-2.4.46-o111k-x64是一个用于部署和运行Apache HTTP服务器的软件包。 首先,要进行httpd-2.4.46-o111k-x64的配置,需要使用一个文本编辑器打开所安装的httpd.conf文件。该文件位于Apache安装目录下的conf文件夹中。 在httpd.conf文件中,可以设置一些全局的配置选项,包括服务器的监听端口、主机名、日志记录选项等。可以根据自己的需求对这些选项进行相应的修改或配置。 另外,还可以在httpd.conf文件中增加虚拟主机的配置。虚拟主机可以让一个服务器同时提供多个不同的网站或域名。可以根据需要在httpd.conf文件中增加多个虚拟主机的配置,包括指定虚拟主机的域名、文档根目录、日志文件等。 除了httpd.conf文件,还可以使用其他的配置文件来进一步定制和调整httpd-2.4.46-o111k-x64的配置。例如,可以使用.htaccess文件来配置特定目录下的访问控制规则和其他相关选项。 配置完成后,可以使用启动脚本或命令来启动httpd-2.4.46-o111k-x64服务器。启动后,可以通过浏览器访问配置的域名或IP地址,来查看是否成功部署和配置了httpd-2.4.46-o111k-x64服务器。 总结来说,httpd-2.4.46-o111k-x64配置主要包括修改httpd.conf文件中的全局配置选项和虚拟主机配置,以及使用其他相关配置文件进行特定定制。配置完成后,可以启动服务器并通过浏览器来访问配置的网站。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值