web基础及http协议 (二)----------Apache相关配置与优化

一、httpd 安装组成

http 服务基于 C/S 结构

1 .常见http 服务器程序

  • httpd apache,存在C10K(10K connections)问题

  • nginx 解决C10K问题lighttpd

  • IIS .asp 应用程序服务器

  • tomcat .jsp 应用程序服务器

  • jetty 开源的servlet容器,基于Java的web容器

  • Resin CAUCHO公司,支持servlets和jsp的引擎

  • webshpere:IBM公司

  • weblogic:BEA,Oracle

  • jboss:RedHat,IBM

  • oc4j:Oracle

2.apache介绍和特点

apache 名字来源,流传最广的解释是(也是最显而易见的):这个名字来自于一个事实:当Apache在1995年初开发的时候,它是由当时最流行的HTTP服务器NCSA HTTPd 1.3的代码修改而成的,因此是"一个修补的(a patchy)”服务器。

HTTP 和 Apache 之间的关系是:HTTP定义了客户端和服务器之间的通信规则,

而 Apache 是一种能够处理这些 HTTP 请求并提供网页内容的 Web 服务器软件。

apache 功能:

  • 提供http协议服务

  • 多个虚拟主机:IP、Port、FQDN   用一台 物理服务器搭建多个网站    百度  jd  淘宝

  • CGI:Common Gateway Interface,通用网关接口,支持动态程序

  • 反向代理

  • 负载均衡

  • 路径别名

  • 丰富的用户认证机制:basic,digest

  • 支持第三方模块

apache特性:

  • 高度模块化:core + modules

  • DSO:Dynamic Shared Object 动态加载/卸载

  • MPM:multi-processing module 多路处理模块

apache 功能多,稳定,处理静态资源优秀

MPM multi-processing module 工作模式

prefork:多进程I/O模型,每个进程响应一个请求,CentOS 7 httpd默认模型一个主进程:生成和回收n个子进程,创建套接字,不响应请求多个子进程:工作 work进程,每个子进程处理一个请求;系统初始时,预先生成多个空闲进程,等待请求

Prefork MPM预派生模式,有一个主控制进程,然后生成多个子进程,每个子进程有一个独立的线程响应用户请求,相对比较占用内存,但是比较稳定,可以设置最大和最小进程数,是最古老的一种模式,也是最稳定的模式,适用于访问量不是很大的场景

优点:稳定

缺点:慢,占用资源,不适用于高并发场景

​[root@centos1 ~]#rpm -q httpd
未安装软件包 httpd 
[root@centos1 ~]#yum install httpd -y
[root@centos1 ~]#systemctl start httpd
[root@centos1 ~]#​

如果是yum安装,默认是prefork模型

worker:复用的多进程I/O模型,多进程多线程,IIS使用此模型

一个主进程:生成m个子进程,每个子进程负责生个n个线程,每个线程响应一个请求,并发响应请求:m*n

worker MPM是一种多进程和多线程混合的模型,有一个控制进程,启动多个子进程,每个子进程里面包含固定的线程,使用线程程来处理请求,当线程不够使用的时候会再启动一个新的子进程,然后在进程里面再启动线程处理请求,由于其使用了线程处理请求,因此可以承受更高的并发。

优点:相比prefork 占用的内存较少,可以同时处理更多的请求

缺点:使用keep-alive的长连接方式,某个线程会一直被占据,即使没有传输数据,也需要一直等待到超时才会被释放。如果过多的线程,被这样占据,也会导致在高并发场景下的无服务线程可用。(该问题在prefork模式下,同样会发生)

event:事件驱动模型(worker模型的变种),CentOS8 默认模型

event MPM是Apache中最新的模式,2012年发布的apache 2.4.X系列正式支持event 模型. 属于事件驱动模型(epoll),每个进程响应多个请求,在现在版本里的已经是稳定可用的模式。

优点:单线程响应多请求,占据更少的内存,高并发下表现更优秀,会有一个专门的线程来管理keep-alive类型的线程,当有真实请求过来的时候,将请求传递给服务线程,执行完毕后,又允许它释放

缺点:没有线程安全控制

centos 版本不一样,可能默认工作模式不一样,centos7 默认是prefork模式

3.Httpd 安装和相关文件

3.1 包安装httpd并启动httpd服务

版本说明:

CentOS 7 以上,默认系统是httpd 2.4,CentOS 6 版默认为httpd 2.2

Ubuntu 18.04 默认 Apache/2.4.29

安装方式:

  • 包安装: centos发行版,稳定,建议使用

  • 编译:定制或特殊需求

​
​[root@centos1 ~]#rpm -q httpd
未安装软件包 httpd 
[root@centos1 ~]#yum install httpd -y
[root@centos1 ~]#systemctl start httpd
[root@centos1 ~]#

3.2 httpd-2.4 相关文件

配置文件:

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

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

  • /etc/httpd/conf.d/conf.modules.d/ 模块加载的配置文件

检查配置语法:httpd -t 或 apache2 -t

服务单元文件:

  • /usr/lib/systemd/system/httpd.service

  • 配置文件:/etc/sysconfig/httpd

服务控制和启动

  • systemctl enable|disable httpd.service

  • systemctl {start|stop|restart|status|reload} httpd.service

  • apachectl start|stop|restart|configtest

  • service httpd start|stop|restart|configtest

站点网页文档根目录:/var/www/html

模块文件路径:

  • /etc/httpd/modules

  • /usr/lib64/httpd/modules

主服务器程序文件:/usr/sbin/httpd

3.3 CentOS 7 编译安装httpd 2.4

编译说明和准备

APR:Apache portable Run-time libraries,Apache可移植运行库,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。在早期的Apache版本中,应用程序本身必须能够处理各种具体操作系统平台的细节,并针对不同的平台调用不同的处理函数随着Apache的进一步开发,Apache组织决定将这些通用的函数独立出来并发展成为一个新的项目。这样,APR的开发就从Apache中独立出来,Apache仅仅是使用 APR而已。目前APR主要还是由Apache使用,由于APR的较好的移植性,因此一些需要进行移植的C程序也开始使用APR,开源项目:比如用于服务器压力测试的Flood loader tester

Apache安装


  Apache即阿帕奇是一款开源的、世界使用排名第一的Web服务器软件,其特点是简单高效、稳定安全所以被广泛应用于计算机技术的各个领域,但现在由于其抗并发性问题现在新公司大部分都使用Nginx代替。

2、Yum安装
①yum安装与其他程序一样可以直接使用命令:yum install  httpd  -y。

②安装过程中注意查看提示信息,若无外网则需要配置本地yum源进行安装。

③出现以下提示即表示安装成功。注意:若出现error字样则表示安装出错!!!

​[root@centos1 ~]#rpm -q httpd
未安装软件包 httpd 
[root@centos1 ~]#yum install httpd -y
[root@centos1 ~]#systemctl start httpd
[root@centos1 ~]#

④ yum安装默认的主配置文件位置: /etc/httpd/conf/httpd.conf

⑤ yum安装默认的主页面配置文件夹位置: /var/www/html/

⑥ yum安装默认的日志文件位置:/var/log/httpd/access_log  此为正常日志记录,/var/log/httpd/error此为错误日志记录。

二、httpd常见配置

1.指定服务器名

[root@centos1 ~]#cd /etc/httpd/conf/
[root@centos1 conf]#ls
httpd.conf  magic
[root@centos1 conf]#cp httpd.conf httpd.conf.bak
[root@centos1 conf]#ls
httpd.conf  httpd.conf.bak  magic
[root@centos1 conf]#httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::183e:c32:9272:8ece. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@centos1 conf]#vim /etc/httpd/conf/httpd.conf95 ServerName www.example.com:80
[root@centos1 conf]#httpd -t
Syntax OK

2.包含其它配置文件

指令:

Include file-path|directory-path|wildcard
IncludeOptional file-path|directory-path|wildcard

说明:

  • Include和IncludeOptional功能相同,都可以包括其它配置文件

  • 但是当无匹配文件时,include会报错,IncludeOptional会忽略错误

include 子配置文件

[root@node2 ~]#grep -i include /etc/httpd/conf/httpd.conf 
Include conf.modules.d/*.conf#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
# Possible values include: debug, info, notice, warn, error, crit,# If you include a trailing / on /webpath then the server will# To parse .shtml files for server-side includes (SSI):# (You will also need to add "Includes" to the "Options" directive.)AddOutputFilter INCLUDES .shtml
IncludeOptional conf.d/*.conf

总目录

[root@node2 httpd]#grep -i serverroot /etc/httpd/conf/httpd.conf
# with "/", the value of ServerRoot is prepended -- so 'log/access_log'
# with ServerRoot set to '/www' will be interpreted by the
# ServerRoot: The top of the directory tree under which the server's
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# same ServerRoot for multiple httpd daemons, you will need to change at
ServerRoot "/etc/httpd"

3 .监听地址

Listen [IP:]PORT

说明:

(1) 省略IP表示为本机所有IP

(2) Listen指令至少一个,可重复出现多次

[root@centos1 conf]#vim /etc/httpd/conf/httpd.conf
#Listen 80
Listen 192.168.246.7:80
Listen 192.168.246.7:9527
[root@centos1 conf]#systemctl restart httpd
[root@centos1 conf]#httpd -t
Syntax OK
[root@centos1 conf]#

实验1:指明具体地址

验证:

实验2:

验证

/etc/httpd/conf/httpd.conf 一些基础配置

4.隐藏服务器版本信息

再去访问

5.持久连接

Persistent Connection:连接建立,每个资源获取完成后不会断开连接,而是继续等待其它的请求完成,默认开启持久连接

断开条件:

  • 时间限制:以秒为单位, 默认5s,httpd-2.4 支持毫秒级

  • 请求数量: 请求数达到指定值,也会断开

副作用:对并发访问量大的服务器,持久连接会使有些请求得不到响应

折衷:使用较短的持久连接时间

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

下图test是自定义  .conf结尾就可以

​
KeepAlive On|Off       # 开启或关闭长连接
KeepAliveTimeout 15      #连接持续15s,可以以ms为单位,默认值为5s
MaxKeepAliveRequests 500  #持久连接最大接收的请求数,默认值100

进入7-2

安装

测试方法:

6.DSO (Dynamic Shared Object)

Dynamic Shared Object,加载动态模块配置,不需重启即生效动态模块所在路径: /usr/lib64/httpd/modules/

主配置 /etc/httpd/conf/httpd.conf 文件中指定加载模块配置文件

查看静态编译的模块:httpd -l

查看静态编译及动态装载的模块:httpd -M

[root@centos1 html]#httpd -M|grep basicauth_basic_module (shared)
[root@centos1 html]#
[root@centos1 html]#
[root@centos1 html]#
[root@centos1 html]#pwd
/var/www/html
[root@centos1 html]#cd /etc/httpd/
[root@centos1 httpd]#ls
conf  conf.d  conf.modules.d  logs  modules  run
[root@centos1 httpd]#cd conf.modules.d/
[root@centos1 conf.modules.d]#ls
00-base.conf  00-dav.conf  00-lua.conf  00-mpm.conf  00-proxy.conf  00-systemd.conf  01-cgi.conf
[root@centos1 conf.modules.d]#vim 00-base.conf 1 #2 # This file loads most of the modules included with the Apache HTTP3 # Server itself.4 #5 6 LoadModule access_compat_module modules/mod_access_compat.so7 LoadModule actions_module modules/mod_actions.so8 LoadModule alias_module modules/mod_alias.so9 LoadModule allowmethods_module modules/mod_allowmethods.so10 #LoadModule auth_basic_module modules/mod_auth_basic.so11 LoadModule auth_digest_module modules/mod_auth_digest.so12 LoadModule authn_anon_module modules/mod_authn_anon.so13 LoadModule authn_core_module modules/mod_authn_core.so14 LoadModule authn_dbd_module modules/mod_authn_dbd.so15 LoadModule authn_dbm_module modules/mod_authn_dbm.so16 LoadModule authn_file_module modules/mod_authn_file.so17 LoadModule authn_socache_module modules/mod_authn_socache.so18 LoadModule authz_core_module modules/mod_authz_core.so19 LoadModule authz_dbd_module modules/mod_authz_dbd.so20 LoadModule authz_dbm_module modules/mod_authz_dbm.so21 LoadModule authz_groupfile_module modules/mod_authz_groupfile.so22 LoadModule authz_host_module modules/mod_authz_host.so23 LoadModule authz_owner_module modules/mod_authz_owner.so24 LoadModule authz_user_module modules/mod_authz_user.so25 LoadModule autoindex_module modules/mod_autoindex.so26 LoadModule cache_module modules/mod_cache.so27 LoadModule cache_disk_module modules/mod_cache_disk.so28 LoadModule data_module modules/mod_data.so29 LoadModule dbd_module modules/mod_dbd.so30 LoadModule deflate_module modules/mod_deflate.so
"00-base.conf" 77L, 3740C 已写入                                                            
[root@centos1 conf.modules.d]#systemctl restart httpd
[root@centos1 conf.modules.d]#httpd -M|grep basic
[root@centos1 conf.modules.d]#

7.MPM (Multi-Processing Module)多路处理模块

httpd 支持三种MPM工作模式:prefork, worker, event

[root@centos7 ~]#vim /etc/httpd/conf.modules.d/00-mpm.conf
[root@centos7 ~]#grep Load /etc/httpd/conf.modules.d/00-mpm.conf 
# one of the following LoadModule lines. See the httpd.conf(5) man
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
#LoadModule mpm_event_module modules/mod_mpm_event.so
[root@centos7 ~]#httpd -M | grep mpm
AH00558: httpd: Could not reliably determine the server's fully qualified domain 
name, using centos8.localdomain. Set the 'ServerName' directive globally to 
suppress this messagempm_prefork_module (shared)

8. prefork模式相关的配置

StartServers       100
MinSpareServers   50
MaxSpareServers   80
ServerLimit     2560 #最多进程数,最大值 20000
MaxRequestWorkers    2560 #最大的并发连接数,默认256
MaxConnectionsPerChild  4000 #子进程最多能处理的请求数量。在处理MaxRequestsPerChild 个
请求之后,子进程将会被父进程终止,这时候子进程占用的内存就会释放(为0时永远不释放)
MaxRequestsPerChild 4000  #从 httpd.2.3.9开始被MaxConnectionsPerChild代替

[root@centos1 conf.modules.d]#vim 00-mpm.conf 
# Select the MPM module which should be used by uncommenting exactly
# one of the following LoadModule lines:# prefork MPM: Implements a non-threaded, pre-forking web server
# See: http://httpd.apache.org/docs/2.4/mod/prefork.html
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so# worker MPM: Multi-Processing Module implementing a hybrid
# multi-threaded multi-process web server
# See: http://httpd.apache.org/docs/2.4/mod/worker.html
#
#LoadModule mpm_worker_module modules/mod_mpm_worker.so# event MPM: A variant of the worker MPM with the goal of consuming
# threads only for connections with active processing
# See: http://httpd.apache.org/docs/2.4/mod/event.html
#
#LoadModule mpm_event_module modules/mod_mpm_event.soStartServers 10
[root@centos1 conf.modules.d]#systemctl restart httpd
[root@centos1 conf.modules.d]#pstree -p|grep httpd|-httpd(7485)-+-httpd(7486)|             |-httpd(7487)|             |-httpd(7488)|             |-httpd(7489)|             |-httpd(7490)|             |-httpd(7491)|             |-httpd(7493)|             |-httpd(7495)|             |-httpd(7496)|             `-httpd(7497)
[root@centos1 conf.modules.d]#

9.worker和event 模式相关的配置

ServerLimit         16  #最多worker进程数 Upper limit on configurable number of 
processes
StartServers        10  #Number of child server processes created at startup
MaxRequestWorkers  150  #Maximum number of connections that will be processed 
simultaneously
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25  #Number of threads created by each child process

10.定义Main server的文档页面路径

DocumentRoot   "/path”
<directory /path>Require all granted
</directory>
  • DocumentRoot指向的路径为URL路径的起始位置

  • /path 必须显式授权后才可以访问

[root@centos1 html]#vim /etc/httpd/conf/httpd.conf
120 DocumentRoot "/data/html"
121 
122 <Directory "/data/html">
123     # Allow open access:
124     Require all granted
125 </Directory>
126 #
127 # Relax access to content within /var/www.
[root@centos1 html]#mkdir /data
[root@centos1 html]#mkdir /data/html
[root@centos1 html]#cd /data/html
[root@centos1 html]#ls
[root@centos1 html]#echo data data > index.html
[root@centos1 html]#ls
index.html
[root@centos1 html]#pwd
/data/html
[root@centos1 html]#cat /data/html/index.html 
data data
[root@centos1 html]#httpd -t
Syntax OK
[root@centos1 html]#systemctl restart httpd
[root@centos1 html]#

去检测:

别名 alias

[root@centos1 opt]#vim /etc/httpd/conf.d/test.conf 
KeepAlive On
KeepAliveTimeout 1000
MaxKeepAliveRequests 1<Directory "/opt/blog"># Allow open access:Require all granted
</Directory>alias   /test   /opt/blog/
"/etc/httpd/conf.d/test.conf" 12L, 177C 已写入
[root@centos1 opt]#systemctl restart httpd
[root@centos1 opt]#

11. 定义站点默认主页面文件

当我们访问服务器时 省略了最后的文件,默认自动会加上 index.html这个是可以修改的

DirectoryIndex index.php index.html

​
[root@centos1 ~]#grep -n index /etc/httpd/conf/httpd.conf
169:    DirectoryIndex index.html
[root@centos1 ~]#

去浏览器访问

针对目录和URL实现访问控制

Options 指令

后跟1个或多个以空白字符分隔的选项列表,在选项前的+,-表示增加或删除指定选项

Options 可以写在目录里 < > 也可以写在外面

接下来:

[root@centos1 ~]#vim /etc/httpd/conf.d/test.conf 
KeepAlive On
KeepAliveTimeout 1000
MaxKeepAliveRequests 1<Directory "/opt/blog"># Allow open access:Require all grantedoptions Indexes
</Directory>alias   /test   /opt/blog/
[root@centos1 ~]#systemctl restart httpd

再去访问不支持

[root@centos1 ~]#vim /etc/httpd/conf.d/test.conf
<Directory "/opt/blog"># Allow open access:Require all grantedoptions Indexes FollowSymLinks
</Directory>alias   /test   /opt/blog/
[root@centos1 ~]#systemctl restart httpd

再去访问

12.虚拟主机

httpd 支持在一台物理主机上实现多个网站,即多虚拟主机

网站的唯一标识:

  • IP相同,但端口不同

  • IP不同,但端口均为默认端口

  • FQDN不同, IP和端口都相同

多虚拟主机有三种实现方案:

  • 基于ip:为每个虚拟主机准备至少一个ip地址

  • 基于port:为每个虚拟主机使用至少一个独立的port

  • 基于FQDN:为每个虚拟主机使用至少一个FQDN,请求报文中首部 Host:www.kgc.com

理解:

基于ip地址

192.168.246.7 ---------> jd

192.168.246.8---------> taobao

基于端口

192.168.246.7:80 ---------> jd

192.168.246.7:800--------> taobao

基于域名

www.lucky.com  --------> lucky

www.cloud.com  ---------> cloud

 虚拟主机的三种实现方式:基于IP、基于端口、基于域名; 最常用的是   基于域名

[root@centos1 ~]#cd /usr/share/doc/httpd-
httpd-2.4.6/       httpd-tools-2.4.6/ 
[root@centos1 ~]#cd /usr/share/doc/httpd-2.4.6/
[root@centos1 httpd-2.4.6]#lsOUT_APACHE    httpd-default.conf    httpd-manual.conf              httpd-vhosts.conf  proxy-html.conf
?HANGES         httpd-info.conf       httpd-mpm.conf                 LICENSE            README
httpd-dav.conf  httpd-languages.conf  httpd-multilang-errordoc.conf  NOTICE             VERSIONING
[root@centos1 httpd-2.4.6]#vim httpd-vhosts.conf

12.1 基于ip地址

[root@centos1 html]#vim /etc/httpd/conf.d/test.conf 
KeepAlive On
KeepAliveTimeout 1000
MaxKeepAliveRequests 1<Directory "/opt/html">AllowOverride None# Allow open access:Require all grantedoptions Indexes FollowSymLinks
</Directory><VirtualHost 192.168.246.7>ServerAdmin support@jfedu.netDocumentRoot "/opt/html/7"ServerName www.accp.comErrorLog "logs/7_error_log"CustomLog "logs/7_access_log" common
</VirtualHost><VirtualHost 192.168.246.111>ServerAdmin support@jfedu.netDocumentRoot "/opt/html/111"ServerName www.accp.comErrorLog "logs/111_error_log"CustomLog "logs/111_access_log" common
</VirtualHost>
[root@centos1 opt]#cd /opt
[root@centos1 opt]#mkdir html
mkdir: 无法创建目录"html": 文件已存在
[root@centos1 opt]#mkdir html/{7,111}
[root@centos1 opt]#tree
bash: tree: 未找到命令...
[root@centos1 opt]#ls
blog  html  test.exe  test.zz
[root@centos1 opt]#cd html/
[root@centos1 html]#ls
111  7  {7.111}
[root@centos1 html]#echo 7 > 7/index.html
[root@centos1 html]#echo 111 > 111/index.html
[root@centos1 html]#cat 7/index.html 
7
[root@centos1 html]#cat 111/index.html 
111
[root@centos1 html]#httpd -t
Syntax OK
[root@centos1 html]#systemctl restart httpd
[root@centos1 html]#ifconfig ens33:0 192.168.246.111/24

检测:

12.2 基于端口地址

[root@centos1 html]#vim /etc/httpd/conf.d/test.conf 
Listen 9527
KeepAlive On
KeepAliveTimeout 1000
MaxKeepAliveRequests 1<Directory "/opt/html">AllowOverride None# Allow open access:Require all grantedoptions Indexes FollowSymLinks
</Directory><VirtualHost 192.168.246.7:80>ServerAdmin support@jfedu.netDocumentRoot "/opt/html/7"ServerName www.accp.comErrorLog "logs/7_error_log"CustomLog "logs/7_access_log" common
</VirtualHost><VirtualHost 192.168.246.7:9527>ServerAdmin support@jfedu.netDocumentRoot "/opt/html/111"ServerName www.accp.comErrorLog "logs/111_error_log"CustomLog "logs/111_access_log" common
</VirtualHost>
[root@centos1 html]#systemctl start httpd

检测:

12.3 基于域名

[root@centos1 html]#vim /etc/httpd/conf.d/test.conf 
Listen 9527
KeepAlive On
KeepAliveTimeout 1000
MaxKeepAliveRequests 1<Directory "/opt/html">AllowOverride None# Allow open access:Require all grantedoptions Indexes FollowSymLinks
</Directory><VirtualHost 192.168.246.7>ServerAdmin support@jfedu.netDocumentRoot "/opt/html/7"ServerName www.kgc.com
#   ErrorLog "logs/7_error_log"
#   CustomLog "logs/7_access_log" common
</VirtualHost><VirtualHost 192.168.246.7>ServerAdmin support@jfedu.netDocumentRoot "/opt/html/111"ServerName www.zzz.com
#   ErrorLog "logs/111_error_log"
#   CustomLog "logs/111_access_log" common
</VirtualHost>
[root@centos1 html]#systemctl start httpd
[root@centos1 html]#systemctl restart httpd
[root@centos1 html]#

验证:

13.基于客户端 IP 地址实现访问控制

黑名单,不能有失败,至少有一个成功匹配才成功,即失败优先

<RequireAll>
RequireAll all granted
RequireAll not ip 172.16.1.1   #拒绝特定IP
</RequireAll>

白名单,多个语句有一个成功,则成功,即成功优先

<RequireAny>
RequireAny all denied
require ip 172.16.1.1   #允许特定IP
</RequireAny>

实验:

[root@centos1 html]#vim /etc/httpd/conf.d/test.conf
<directory /mnt>
<RequireAll>Require all grantedRequire not ip 192.168.246.1
</RequireAll>
</directory>alias /mnt  /mnt/html
[root@centos1 html]#mkdir /mnt/html
[root@centos1 html]#echo /mnt/html > /mnt/html/index.html
[root@centos1 html]#cat /mnt/html/index.html
/mnt/html
[root@centos1 html]#systemctl restart httpd

验证:

去虚拟机访问:

去真机网页验证

14.日志

三、Web相关工具

1.Wget相关工具

格式:

wget [OPTION]... [URL]...

常用选项:

-q 静默模式
-c 断点续传
-P /path 保存在指定目录
-O filename 保存为指定文件名,filename 为 - 时,发送至标准输出
--limit-rate= 指定传输速率,单位K,M等

例子:

[root@centos7 ~]#wget --limit-rate 1M -P /data https://mirrors.aliyun.com/centos/8/isos/x86_64/CentOS-8-x86_64-1905-dvd1.iso

2.curl    文字版浏览器

curl是基于URL语法在命令行方式下工作的文件传输工具,它支持FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE及LDAP等协议。curl支持HTTPS认证,并且支持HTTP的POST、PUT等方法, FTP上传, kerberos认证,HTTP上传,代理服务器,cookies,用户名/密码认证, 下载文件断点续传,上载文件断点续传, http代理服务器管道( proxy tunneling),还支持IPv6,socks5代理服务器,通过http代理服务器上传文件到FTP服务器等,功能十分强大.

格式:

curl [options] [URL...]

常用选项

-A/--user-agent <string> 设置用户代理发送给服务器
-e/--referer <URL> 来源网址
--cacert <file> CA证书 (SSL)
-k/--insecure   允许忽略证书进行 SSL 连接
--compressed 要求返回是压缩的格式
-H/--header "key:value” 自定义首部字段传递给服务器
-i 显示页面内容,包括报文首部信息
-I/--head 只显示响应报文首部信息
-D/--dump-header <file>将url的header信息存放在指定文件中
--basic 使用HTTP基本认证
-u/--user <user[:password]>设置服务器的用户和密码
-L   如果有3xx响应码,重新发请求到新位置
-O 使用URL中默认的文件名保存文件到本地
-o <file> 将网络文件保存为指定的文件中
--limit-rate <rate> 设置传输速度
-0/--http1.0 数字0,使用HTTP 1.0
-v/--verbose 更详细
-C 选项可对文件使用断点续传功能
-c/--cookie-jar <file name> 将url中cookie存放在指定文件中
-x/--proxy <proxyhost[:port]> 指定代理服务器地址
-X/--request <command> 向服务器发送指定请求方法
-U/--proxy-user <user:password> 代理服务器用户和密码
-T 选项可将指定的本地文件上传到FTP服务器上
--data/-d 方式指定使用POST方式传递数据
-s --silent   Silent mode
-b name=data 从服务器响应set-cookie得到值,返回给服务器
-w <format> 显示相应的指定的报文信息,如:%{http_code},%{remote_ip}等
-m, --max-time <time> 允许最大传输时间

-I/--head 只显示响应报文首部信息

[root@centos7 ~]#curl -I http://www.163.com

[root@localhost ~]#curl www.163.com -vA chrome

-L   如果有3xx响应码,重新发请求到新位置

-v/--verbose 更详细

补充:

提取状态码

[root@centos1 ~]#curl -s -I -m10 -o /dev/null ? -w %{http_code} http://www.baidu.com/

提取远端ip

[root@centos1 ~]#curl -s -I -m10 -o /dev/null   -w %{remote_ip} http://www.baidu.com/

提取本地ip (自己)

[root@centos1 ~]#curl -s -I -m10 -o /dev/null ? -w %{local_ip} http://www.baidu.com/

[root@centos1 ~]#curl -s -I -m10 -o /dev/null   -w %{local_port} http://www.baidu.com/

[root@centos1 ~]#curl -s -I -m10 -o /dev/null ? -w %{remote_port} http://www.baidu.com/

汇总:

curl -s -I -m10 -o /dev/null   -w %{http_code} http://www.baidu.com/
curl -s -I -m10 -o /dev/null   -w %{remote_ip} http://www.baidu.com/
curl -s -I -m10 -o /dev/null   -w %{local_ip} http://www.baidu.com/
curl -s -I -m10 -o /dev/null   -w %{local_port} http://www.baidu.com/
curl -s -I -m10 -o /dev/null   -w %{remote_port} http://www.baidu.com/

3.压力测试工具

httpd的压力测试工具:

  • ab, webbench, http_load, seige

  • Jmeter 开源

  • Loadrunner 商业,有相关认证

  • tcpcopy:网易,复制生产环境中的真实请求,并将之保存

ab 来自httpd-tools包

命令格式:

ab [OPTIONS] URL

选项:

-n:总请求数
-c:模拟的并发数
-k:以持久连接模式测试

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/697071.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

选择 Python IDE(VSCode、Spyder、Visual Studio 2022和 PyCharm)

前言 当选择 Python 开发工具时&#xff0c;你需要考虑自己的需求、偏好和项目类型。下面是对VSCode、Spyder、Visual Studio 2022和 PyCharm的对比推荐总结&#xff1a; 结论 1、如果你专注于“数据科学”&#xff0c;选择SpyDer没错。 内容 Visual Studio Code (VS Code)…

react项目中的redux以及react-router-dom

扫盲知识点&#xff1a; 1 传递自定义事件&#xff1a; <button onClick{(e)>{change(e)}}>获取事件对象e</button> 将事件对象e传递到了change的这个方法中。 2 同时传递自定义事件和参数&#xff1a; <button onClick{(e)>{change(‘我…

基于微信小程序失物招领系统设计与实现(PHP后台+Mysql)可行性分析

博主介绍&#xff1a;黄菊华老师《Vue.js入门与商城开发实战》《微信小程序商城开发》图书作者&#xff0c;CSDN博客专家&#xff0c;在线教育专家&#xff0c;CSDN钻石讲师&#xff1b;专注大学生毕业设计教育和辅导。 所有项目都配有从入门到精通的基础知识视频课程&#xff…

CleanMyMac2024苹果电脑清理工具最新使用全面评价

作为软件评价专家&#xff0c;我对CleanMyMac X进行了全面的评估&#xff0c;以下是我的详细评价&#xff1a; CleanMyMac X4.14.6全新版下载如下: https://wm.makeding.com/iclk/?zoneid49983 一、功能 CleanMyMac X的功能相当全面&#xff0c;几乎涵盖了Mac电脑清理所需的…

nginx 具体介绍

一&#xff0c;nginx 介绍 &#xff08;一&#xff09;nginx 与apache 1&#xff0c; Apache event 模型 相对于 prefork 模式 可以同时处理更多的请求 相对于 worker 模式 解决了keepalive场景下&#xff0c;长期被占用的线程的资源浪费问题 因为有监听线程&#…

【数据结构】链式队列

链式队列实现&#xff1a; 1.创建一个空队列 2.尾插法入队 3.头删法出队 4.遍历队列 一、main函数 #include <stdio.h> #include "./3.linkqueue.h" int main(int…

文档控件DevExpress Office File API v23.2新版亮点 - 支持SVG

DevExpress Office File API是一个专为C#, VB.NET 和 ASP.NET等开发人员提供的非可视化.NET库。有了这个库&#xff0c;不用安装Microsoft Office&#xff0c;就可以完全自动处理Excel、Word等文档。开发人员使用一个非常易于操作的API就可以生成XLS, XLSx, DOC, DOCx, RTF, CS…

数据结构之单链表的操作

main函数 #include <stdio.h> #include "./03_linkList.h" int main(int argc, const char *argv[]) { linkList* head creatr_linkList(); insertHead_linkL…

运维SRE-19 网站Web中间件服务-http-nginx

Ans自动化流程 1.网站集群核心协议&#xff1a;HTTP 1.1概述 web服务&#xff1a;网站服务&#xff0c;网站协议即可. 协议&#xff1a;http协议,https协议 服务&#xff1a;Nginx服务&#xff0c;Tengine服务....1.2 HTTP协议 http超文本传输协议&#xff0c;负责数据在网站…

更高效的构建工具-vite

更高效的构建工具-vite 前言Vite是什么Vite和webpack的比较1. 运行原理2. 使用成本 Vite的初体验 前言 首先我们要认识什么时构建工具&#xff1f; 企业级项目都具备什么功能呢&#xff1f; Typescript&#xff1a;如果遇到ts文件&#xff0c;我们需要使用tsc将typescript代码…

Android约束布局中用ConstraintHelper实现过渡动画效果

前些天发现了一个蛮有意思的人工智能学习网站,8个字形容一下"通俗易懂&#xff0c;风趣幽默"&#xff0c;感觉非常有意思,忍不住分享一下给大家。 &#x1f449;点击跳转到教程 一.创建一个类CircularRevealHelper继承ConstraintHelper代码如下 /*** Author: ly* Da…

【Linux从青铜到王者】 基础IO

本篇重点&#xff1a;文件描述符&#xff0c;重定向&#xff0c;缓冲区&#xff0c;磁盘结构&#xff0c;文件系统&#xff0c;inode理解文件的增删查改&#xff0c;查找一个文件为什么一定要有路径&#xff0c;动静态库&#xff0c;有的时候为什么找不到库&#xff0c;动态库的…

JavaWeb——003Axios Vue组件库(Element)

目录 一、Ajax 1、同步与异步​编辑 2、原生Ajax&#xff08;繁琐&#xff09;​编辑 2.1、写一个简易的Ajax 3、Axios&#xff08;推荐使用&#xff09;​编辑 3.1、Axios入门 3.2、Axios请求方式别名 3.3、案例&#xff1a;基于Vue及Axios完成数据的动态加载展示​编…

Flink CDC 3.0 表结构变更时导致webUI接口无反应原因

Flink CDC 3.0 表结构变更时导致webUI接口无反应&#xff01; 原因&#xff1a;因为deliverCoordinationRequestToCoordinator和requestJob都是SchedulerNG中方法&#xff0c;该类的线程模型是单线程执行&#xff0c;所以在deliverCoordinationRequestToCoordinator执行表结构…

mysql创建数据库,用户授权

一、创建用户 CREATE USER 用户名% IDENTIFIED BY 密码; flush privileges; 二、更新用户密码 update mysql.user set authentication_stringpassword("密码") where userroot; flush privileges; 三、允许root远程登录 update user set host % where user r…

AIoT网关 人工智能物联网网关

AIoT(人工智能物联网)作为新一代技术的代表&#xff0c;正以前所未有的速度改变着我们的生活方式。在这个智能时代&#xff0c;AIoT网关的重要性日益凸显。它不仅是连接智能设备和应用的关键&#xff0c;同时也是实现智能化家居、智慧城市和工业自动化的必备技术。      一…

c# entity freamwork 判断是否存在

在 Entity Framework (EF) 中&#xff0c;你可以使用 LINQ 查询来判断数据库中是否存在特定条件的记录。以下是一些常见的方法&#xff1a; 使用 Any 方法: using (var context new YourDbContext()) {bool exists context.YourEntity.Any(e > e.Property yourValue);i…

【linux进程间通信(二)】共享内存详解以及进程互斥概念

&#x1f493;博主CSDN主页:杭电码农-NEO&#x1f493;   ⏩专栏分类:Linux从入门到精通⏪   &#x1f69a;代码仓库:NEO的学习日记&#x1f69a;   &#x1f339;关注我&#x1faf5;带你学更多操作系统知识   &#x1f51d;&#x1f51d; 进程间通信 1. 前言2. 共享内…

2024年2月23日 晨会汇报

Good morning, colleages! This is /ˈdɑː.tʃi/ speaking. As for my report today, I decide to wing it, so I didnt prepare a script. Now, Ill share an update about my recent work activities which encompasses two key area: a summary of my work yesterday a…

【Go channel如何控制goroutine并发执行顺序?】

多个goroutine并发执行时&#xff0c;每一个goroutine抢到处理器的时间点不一致&#xff0c;gorouine的执行本身不能保证顺序。即代码中先写的gorouine并不能保证先执行 思路&#xff1a;使用channel进行通信通知&#xff0c;用channel去传递信息&#xff0c;从而控制并发执行…