httpd安装、配置、编译&三种访问模式控制&https证书的安装&访问实例及排错


1. httpd简介

httpd是Apache超文本传输协议(HTTP)服务器的主程序。被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池。

通常,httpd不应该被直接调用,而应该在类Unix系统中由apachectl调用,在Windows中作为服务运行。

2. httpd版本

本文主要介绍httpd的两大版本,httpd-2.2和httpd-2.4。

  • CentOS6系列的版本默认提供的是httpd-2.2版本的rpm包
  • CentOS7系列的版本默认提供的是httpd-2.4版本的rpm包
2.1 httpd的特性

httpd有很多特性,下面就分别来说说httpd-2.2版本和httpd-2.4版本各自的特性。

版本 特性
2.2 事先创建进程按需维持适当的进程模块化设计,核心比较小,各种功能通过模块添加(包括PHP),支持运行时配置,支持单独编译模块支持多种方式的虚拟主机配置,如基于ip的虚拟主机,基于端口的虚拟主机,基于域名的虚拟主机等支持https协议(通过mod_ssl模块实现)支持用户认证支持基于IP或域名的ACL访问控制机制支持每目录的访问控制(用户访问默认主页时不需要提供用户名和密码,但是用户访问某特定目录时需要提供用户名和密码)支持URL重写支持MPM(Multi Path Modules,多处理模块)。用于定义httpd的工作模型(单进程、单进程多线程、多进程、多进程单线程、多进程多线程)
2.4 httpd-2.4的新特性:MPM支持运行DSO机制(Dynamic Share Object,模块的动态装/卸载机制),以模块形式按需加载支持event MPM,eventMPM模块生产环境可用支持异步读写支持每个模块及每个目录分别使用各自的日志级别每个请求相关的专业配置,使用来配置增强版的表达式分析器支持毫秒级的keepalive timeout基于FQDN的虚拟主机不再需要NameVirtualHost指令支持用户自定义变量支持新的指令(AllowOverrideList)降低对内存的消耗
工作模型 工作方式
prefork 多进程模型,预先生成进程,一个请求用一个进程响应一个主进程负责生成n个子进程,子进程也称为工作进程每个子进程处理一个用户请求,即使没有用户请求,也会预先生成多个空闲进程,随时等待请求到达,最大不会超过1024个
worker 基于线程工作,一个请求用一个线程响应(启动多个进程,每个进程生成多个线程)
event 基于事件的驱动,一个进程处理多个请求
2.2 httpd-2.4新增的模块

httpd-2.4在之前的版本基础上新增了几大模块,下面就几个常用的来介绍一下。

模块 功能
mod_proxy_fcgi 反向代理时支持apache服务器后端协议的模块
mod_ratelimit 提供速率限制功能的模块
mod_remoteip 基于ip的访问控制机制被改变,不再支持使用Order,Deny,Allow来做基于IP的访问控制

3. httpd基础

3.1 httpd自带的工具程序
工具 功能
htpasswd basic认证基于文件实现时,用到的帐号密码生成工具
apachectl httpd自带的服务控制脚本,支持start,stop,restart
apxs 由httpd-devel包提供的,扩展httpd使用第三方模块的工具
rotatelogs 日志滚动工具
suexec 访问某些有特殊权限配置的资源时,临时切换至指定用户运行的工具
ab apache benchmark,httpd的压力测试工具
3.2 rpm包安装的httpd程序环境
文件/目录 对应的功能
/var/log/httpd/access.log 访问日志
/var/log/httpd/error_log 错误日志
/var/www/html/ 站点文档目录
/usr/lib64/httpd/modules/ 模块文件路径
/etc/httpd/conf/httpd.conf 主配置文件
/etc/httpd/conf.modules.d/*.conf 模块配置文件
/etc/httpd/conf.d/*.conf 辅助配置文件

mpm:以DSO机制提供,配置文件为/etc/httpd/conf.modules.d/00-mpm.conf

3.3 web相关的命令
3.3.1 curl命令

curl是基于URL语法在命令行方式下工作的文件传输工具,它支持FTP,FTPS,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE及LDAP等协议。

curl支持以下功能:

  • https认证
  • http的POST/PUT等方法
  • ftp上传
  • kerberos认证
  • http上传
  • 代理服务器
  • cookies
  • 用户名/密码认证
  • 下载文件断点续传
  • socks5代理服务器
  • 通过http代理服务器上传文件到ftp服务器
    //语法:curl [options] [URL …]
    //常用的options:
    -A/–user-agent //设置用户代理发送给服务器
    -basic //使用Http基本认证
    –tcp-nodelay //使用TCP_NODELAY选项
    -e/–referer //来源网址
    –cacert //CA证书(SSL)
    –compressed //要求返回时压缩的格式
    -H/–header //自定义请求首部信息传递给服务器
    -I/–head //只显示响应报文首部信息
    –limit-rate //设置传输速度
    -u/–user <user[:password]> //设置服务器的用户和密码
    -0/–http1 //使用http 1.0版本,默认使用1.1版本。这个选项是数字0而不是字母o
    -o/–output //把输出写到文件中
    -#/–progress-bar //进度条显示当前的传送状态
//通过curl下载文件

[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# curl -o myblog.html http://blog.51cto.com/itchentao
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   312  100   312    0     0   2012      0 --:--:-- --:--:-- --:--:--  2012
[root@localhost ~]# ls
anaconda-ks.cfg  myblog.html
3.3.2 httpd命令

//语法:httpd [options]
//常用的options:
-l //查看静态编译的模块,列出核心中编译了哪些模块。
//它不会列出使用LoadModule指令动态加载的模块
-M //输出一个已经启用的模块列表,包括静态编译在服务
//器中的模块和作为DSO动态加载的模块
-v //显示httpd的版本,然后退出
-V //显示httpd和apr/apr-util的版本和编译参数,然后退出
-X //以调试模式运行httpd。仅启动一个工作进程,并且
//服务器不与控制台脱离
-t //检查配置文件是否有语法错误

[root@localhost ~]# httpd -l
Compiled in modules:
  core.c
  mod_so.c
  http_core.c
[root@localhost ~]# httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 access_compat_module (shared)
 actions_module (shared)
 alias_module (shared)
 allowmethods_module (shared)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_anon_module (shared)
 authn_core_module (shared)
 authn_dbd_module (shared)
 authn_dbm_module (shared)
 authn_file_module (shared)
 authn_socache_module (shared)
 authz_core_module (shared)
 authz_dbd_module (shared)
 authz_dbm_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_owner_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 brotli_module (shared)
 cache_module (shared)
 cache_disk_module (shared)
 cache_socache_module (shared)
 data_module (shared)
 dbd_module (shared)
 deflate_module (shared)
 dir_module (shared)
 dumpio_module (shared)
 echo_module (shared)
 env_module (shared)
 expires_module (shared)
 ext_filter_module (shared)
 filter_module (shared)
 headers_module (shared)
 include_module (shared)
 info_module (shared)
 log_config_module (shared)
 logio_module (shared)
 macro_module (shared)
 mime_magic_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 remoteip_module (shared)
 reqtimeout_module (shared)
 request_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 slotmem_plain_module (shared)
 slotmem_shm_module (shared)
 socache_dbm_module (shared)
 socache_memcache_module (shared)
 socache_shmcb_module (shared)
 status_module (shared)
 substitute_module (shared)
 suexec_module (shared)
 unique_id_module (shared)
 unixd_module (shared)
 userdir_module (shared)
 version_module (shared)
 vhost_alias_module (shared)
 watchdog_module (shared)
 dav_module (shared)
 dav_fs_module (shared)
 dav_lock_module (shared)
 lua_module (shared)
 mpm_event_module (shared)
 proxy_module (shared)
 lbmethod_bybusyness_module (shared)
 lbmethod_byrequests_module (shared)
 lbmethod_bytraffic_module (shared)
 lbmethod_heartbeat_module (shared)
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 proxy_connect_module (shared)
 proxy_express_module (shared)
 proxy_fcgi_module (shared)
 proxy_fdpass_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_hcheck_module (shared)
 proxy_scgi_module (shared)
 proxy_uwsgi_module (shared)
 proxy_wstunnel_module (shared)
 systemd_module (shared)
 cgid_module (shared)
 http2_module (shared)
 proxy_http2_module (shared)
[root
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值