千家信息网

apache httpd的安装和配置

发表于:2024-10-12 作者:千家信息网编辑
千家信息网最后更新 2024年10月12日,这篇文章主要讲解了"apache httpd的安装和配置",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"apache httpd的安装和配置"吧!安装包
千家信息网最后更新 2024年10月12日apache httpd的安装和配置

这篇文章主要讲解了"apache httpd的安装和配置",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"apache httpd的安装和配置"吧!

安装包

yum -y install httpd

命令

/usr/sbin/httpd

httpd: root:root 主导进程(master process)

httpd: apche:ache 工作进程(work process)

服务

/etc/init.d/httpd

端口:

80 tcp

443 ssl

工作的根目录(相当于程序安装目录)

/etc/httpd

/etc/httpd/conf 配置文件目录

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

/etc/httpd/conf.d/*.conf 这些文件都为主配置文件的一部分,在主配置文件中用include包含进去

/etc/httpd/modules 模块目录

/etc/httpd/logs-->/var/log/httpd 日志目录

日志文件有两类:访问日志access_log,错误日志:err_log

/var/www/

html 静态页面目录

cgi-bin

欢迎页面:

/etc/httpd/conf.d/welcome.conf

不显示欢迎页面

[root@LinuxTest named]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak

[root@LinuxTest named]# /etc/init.d/httpd restart

Stopping httpd: [ OK ]

Starting httpd: [ OK ]

创建测试页面

echo -e "

hello world

hello world

welcome to our website

" >> /var/www/html/index.html

/etc/httpd/conf/httpd.conf 详解

主要分3个大部分,第二部分和第三部分不能同时生效

[root@LinuxTest named]# grep "Section" /etc/httpd/conf/httpd.conf

### Section 1: Global Environment

### Section 2: 'Main' server configuration

### Section 3: Virtual Hosts

Section 1:

ServerRoot "/etc/httpd" 服务器的工作目录,不要轻易改动

Timeout 60 tcp连接未成功建立连接的等待超时时间

KeepAlive Off 是否使用长连接

MaxKeepAliveRequests 100 每个长连接的最大请求数,0表示无限制

KeepAliveTimeout 15 长连接的断开时长,单位秒

MPM Multi Path Modules

prefork 一个请求用一个进程响应

# StartServers: number of server processes to start 启动服务是的进程数

# MinSpareServers: minimum number of server processes which are kept spare 最少空闲进程数

# MaxSpareServers: maximum number of server processes which are kept spare 最大空闲进程数

# ServerLimit: maximum value for MaxClients for the lifetime of the server 指定maxclients的上线值

# MaxClients: maximum number of server processes allowed to start 最多允许多少客户端同时连接

# MaxRequestsPerChild: maximum number of requests a server process serves 一个进程最多相应多少次请求

worker 一个请求用一个线程响应。启动多个进程,每个进程生成多个线程

# StartServers: initial number of server processes to start 启动服务的进程数

# MaxClients: maximum number of simultaneous client connections 最大客户端连接数

# MinSpareThreads: minimum number of worker threads which are kept spare 最小空闲线程

# MaxSpareThreads: maximum number of worker threads which are kept spare 最大空闲线程

# ThreadsPerChild: constant number of worker threads in each server process 一个进程生成多少线程

# MaxRequestsPerChild: maximum number of requests a server process serves 每个进程相应多少请求,0不作限定

event 一个进程处理多个请求

httpd -l 列出当前httpd指定的MPM模型

修改HTTP的启动默认MPM模型

vi /etc/sysconfig/httpd 修改httpd的配置文件

HTTPD=/usr/sbin/httpd.worker

Listen 80 服务监听的端口。IP可以省略,不写IP表示监听所有地址。Listen可以多个

Section 2:

ServerAdmin root@localhost 指定管理员email地址,每个站点都需要指定一个

ServerName www.example.com:80 服务器的名字,反解析IP到FQDN。注意:在虚拟主机,尤其是基于主机名的虚拟主机当中是必须的

DocumentRoot "/var/www/html" 指定文档根目录

定义根目录的访问权限等

Options Indexes FollowSymLinks 可选项:

None 不支持任何选项

Indexes(列出目录内的信息,生产中强烈不建议使用,除非是下载站)

Includes 不安全的,允许服务器端包含(SSI)

FollowSymLinks 跟随符号链接,允许访问符号链接指向的文件,强烈不建议使用

SymLinksifOwnerMatch 允许访问符号链接执行的文件,不建议使用

ExecCGI 允许执行CGI脚本

MultiViews 多功能视图(内容协商机制),除非是支持多语言,否则不建议使用

all 支持所有选项

AllowOverride None 允许覆盖,覆盖下面的2选项.可选项:All,None,AuthConfig(基于账号认证)

htpasswd 创建密码文件(图片2)

-c 创建密码文件

-m md5方式加密

htpasswd -c -m /etc/httpd/conf/htpasswd hadoop

htpasswd -m /etc/httpd/conf/htpasswd hadoop

Order allow,deny order 用于定义基于主机的访问功能。(IP ,网络地址或主机定义访问控制机制),allow和deny按照先后顺序,顺序很关键

Allow from all

或deny from all,allow from 192.168.56.0/24(允许56网段访问),也可以指定IP

DirectoryIndex index.html index.html.var 指定默认访问页面

HostnameLookups Off 在日志中是否把IP反解析成主机名,不建议使用

ErrorLog logs/error_log 错误日志

LogLevel warn 日志级别。include: debug, info, notice, warn, error, crit,alert, emerg.

LogFormat 指定日志格式

Section 3:(图片3)

配置文件语法检查:httpd -t 检查配置文件语法

感谢各位的阅读,以上就是"apache httpd的安装和配置"的内容了,经过本文的学习后,相信大家对apache httpd的安装和配置这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

0