当我们安装了Apache服务时,通常会一同安装一个默认的配置文件(httpd.conf)。其他的配置文件通过‘Include’的包括进来。
改变了配置文件,必须重启服务。
语法规则
- 通常一行一个指令
- 指令的参数必须用空格隔开。如果参数本身含有空格,则需要用‘“’
- 指令大小写不敏感
- 参数大小写敏感
- 以“#”开头则该行为coments,不是有效指令
- 变量可以直接定义:
<IfDefine TEST> Define servername test.example.com </IfDefine>
- 变量还可以从shell的环境变量中读取,并用${VAR}来引用。
- 变量名字中不要包含“:”
- 一行长度有限制。最大的字符数为8190.
- 可用‘
apachectl configtest
’来校验配置文件的语法
模块化
httpd是一个模块化的服务器。核心服务器有最基本的功能的模块。扩展功能可以通过‘modules’来记载到httpd。
server端具体的一些配置讲解
# Specify the web IP and port
Listen 10.66.147.45/8080
# Specify the user and group who can run the apache service
# If the run users are not in the group or the apache user, you need to use 'sudo'
User apache
Group apache
# Specify the administrator mail list
ServerAdmin wlin@redhat.com
# specify your address of the web, usually it should be the host name of the server.
# If your hostname cannot be resolved by dns, then please use IP
ServerName www.example.com:80
# As default, all requests are taken from this directory
DocumentRoot "/var/www/html"
负载均衡相关配置
# 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
# Usually, Let us set the MaxClients as the ServerLimit
<IfModule prefork.c>
StartServers 4
MinSpareServers 3
MaxSpareServers 10
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 10000
</IfModule>
根据这个配置,