Web服务(二)httpd配置参数详细介绍

CentOS 6.5编译安装httpd-2.4.7

一、配置文件和基本格式


配置文件路径:/etc/httpd/conf/httpd.conf

配置参数    值

1、配置指令不区分字符大小写;但是值有可能区分字符大小写

2、有些指令可以重复出现多次

配置文件格式:

1、全局配置

2、主机配置:用于仅提供一个站点

3、虚拟主机:用于提供多个站点(和主机配置不能同时生效)

配置文件语法测试:{service httpd configtest | httpd -t}

二、详细配置

1、监听套接字

#配置文件事例

#Listen 12.34.56.78:80

Listen 80

Listen 8080

Listen 192.168.1.110:8082


此指令可以出现多次;用于指定监听多个不同的套接字:

[Linux]#httpd -t

Syntax OK

[Linux]#service httpd reload

Reloading httpd:

[Linux]#ss -tnl

State      Recv-Q Send-Q                    Local Address:Port                      Peer Address:Port

LISTEN    0      128                                  :::111                                  :::*

LISTEN    0      128                                    *:111                                  *:*

LISTEN    0      128                                  :::8080                                :::*

LISTEN    0      128                                  :::80                                  :::*

LISTEN    0      128                        192.168.1.186:8082                                  *:*

2、配置使用Keep Alive

# KeepAlive: Whether or not to allow persistent connections (more than

# one request per connection). Set to "Off" to deactivate.

#

#KeepAlive On

KeepAlive Off

MaxKeepAliveRequests 100 #持久连接最大请求数

KeepAliveTimeout 15 #超时时间

3、多道处理模块MPM


查看系统默认启用的模块

[Linux]#httpd -l

Compiled in modules:

core.c

prefork.c #默认启用prefork模块

http_core.c

mod_so.c

[Linux]#

#如需启用worker模块;需要更改配置文件

[Linux]#vi /etc/sysconfig/httpd

#HTTPD=/usr/sbin/httpd.worker #启用该项后重启httpd


配置模块信息

[Linux]#vi /etc/httpd/conf/httpd.conf

# prefork MPM

# 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: maximum number of server processes allowed to start

# MaxRequestsPerChild: maximum number of requests a server process serves

prefork 稳定性较好,一个线程崩溃不会影响其他线程

<IfModule prefork.c> 判断prefork模块是否存在

StartServers      8 默认启动的工作进程数;不包含主进程

MinSpareServers    5 最少空闲进程数

MaxSpareServers  20 最大空闲进程数

ServerLimit      256 最大活动进程数

MaxClients      256 最多允许发起的请求的个数

MaxRequestsPerChild  4000 每个子进程在生命周期内所能够服务的最多请求个数

</IfModule>

# worker MPM

# 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

worker 多个进程;一个进程崩溃会影响其下的其他线程

<IfModule worker.c> 判断worker模块是否存在

StartServers        4 启动的子进程的个数

MaxClients        300 并发请求的最大个数

MinSpareThreads    25 最少空闲线程数

MaxSpareThreads    75 最大空闲线程数

ThreadsPerChild    25 每个子进程可生成的线程数

MaxRequestsPerChild  0 每个子进程在生命周期内所能够服务的最多请求个数;0表示不做限定

</IfModule>


4、DSO模块的加载方式

LoadModule module_name /path/to/module

可以使用相对路径和绝对路径;相对路径则对于ServerRoot所定义的位置而言;

更改完成后service httpd reload可生效

# LoadModule foo_module modules/mod_foo.so

#

LoadModule auth_basic_module modules/mod_auth_basic.so

LoadModule auth_digest_module modules/mod_auth_digest.so

LoadModule authn_file_module modules/mod_authn_file.so

LoadModule authn_alias_module modules/mod_authn_alias.so

LoadModule authn_anon_module modules/mod_authn_anon.so

#

#

[Linux]#httpd -M #可以查看系统所有装载模块

Loaded Modules:

core_module (static)

mpm_prefork_module (static)

http_module (static)

so_module (static)

auth_basic_module (shared)

auth_digest_module (shared)

authn_file_module (shared)

authn_alias_module (shared)

5、配置站点根目录和页面属性

# DocumentRoot: The directory out of which you will serve your

# documents. By default, all requests are taken from this directory, but

# symbolic links and aliases may be used to point to other locations.

#

DocumentRoot "/var/www/html"

DocumentRoot "/path/to/somewhere(站点路径)" #格式

# The Options directive is both complicated and important.  Please see 下述站点有配置详细说明

# #options

# for more information.

#

<Directory "/var/www/html"> #页面访问属性

#

#

Options Indexes FollowSymLinks

#

#

#

Indexes 缺少默认页面时;允许将目录中的所有文件已列表形式返回给用户

FollowSymLinks 允许跟随符号链接所指向的原始文件;危险

None 所有都不启用

All 所有都启用

ExecCGI 是否允许使用mod_cgi模块执行CGI脚���

Includes 是否允许使用mod_include模块实现服务器端包含(SSI)

MultiViews 允许使用mod_negotiation实现内容协商

SymLinksIfOwnerMatch 在链接文件属主属组与原始文件的属主属组相同时;允许跟随符号链接所指向的原始文件

#

#

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

#  Options FileInfo AuthConfig Limit

基于主机的访问控制

#

#

AllowOverride None 表示下面这些控制机制是否被禁用;None表示不被禁用

#

# Controls who can get stuff from this server.

#

#allow允许;deny不允许

Order allow,deny #默认deny;没有allow的都deny;可以写多条;自上而下匹配

Allow from all 格式:from IP

Deny

#二者都匹配或二者都无匹配项时,则以后者为准;否则,则以匹配到的为准

</Directory>

#最佳匹配:从列表中找出最小的能匹配到访问者的地址的条目为最终是生效的

#详细参考#allow

6、定义默认主页面

# The index.html.var file (a type-map) is used to deliver content-

# negotiated documents.  The MultiViews Option can be used for the

# same purpose, but it is much slower.

#

DirectoryIndex index.html index.html.var #自左而右依次查找

7、用户目录

# The path to the end user account 'public_html' directory must be

# accessible to the webserver userid.  This usually means that ~userid

权限说明

# must have permissions of 711, ~userid/public_html must have permissions

# of 755, and documents contained therein must be world-readable.

# Otherwise, the client will only receive a "403 Forbidden" message.

#

# See also: #forbidden

#

<IfModule mod_userdir.c>

#

# UserDir is disabled by default since it can confirm the presence

# of a username on the system (depending on home directory

# permissions).

#

UserDir disabled

disabled 禁止

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/39642425cec0705bfb49d94f7af8de3e.html