Apache 配置

Apache 配置,第1张

Apache 配置

1、下载apache

2、 ./configure

--prefix=/usr/local/apache2.2.32

--enable-deflate

--enable-headers

--enable-expires

--enable-modules=most

--enable-so

--with-mpm=worker

--enable-rewrite

3、 make

4、make install

配置文件

一、/usr/local/apache/conf/httpd.conf 内容解析

Server root 服务的根目录

Listen 80 监听的端口

Server admin [email protected]管理员邮箱

Servername www.yeyiboy.com 网站名

Documentroot /usr/local/apache/htdocs 站点目录,需改成自己的站点目录

表示根目录拒绝其他人访问

Options FollowSymLinks

AllowOverride None 禁止相关功能

Order deny,allow 不让任何人访问根目录

Deny from all 不让任何人访问根目录

新增加站点目录,必须增加下面六行,否则网站打不开

把站点目录/usr/local/apache2.2.32/htdocs改成自己的站点目录

Options Indexes FollowSymLinks 如去掉Indexes,站点目录如果没有首页也不会暴露站点目录。为了安全,通常配置会去掉。

AllowOverride None

Order allow,deny

Allow from all

DirectoryIndex index.html 指定访问首页,如果有多个首页,都列出,空格隔开

ErrorLog "logs/error_log" 错误日志

去掉include conf/extra/ httpd-mpm.conf和include conf/extra/ httpd-vhosts.conf 前面的#号

二、/usr/local/apache/conf/extra 扩展的配置文件

1、 httpd-mpm.conf

工作模式为prefork模式。默认为该模式。#Apache共两种模式,prefork和worker

StartServers 5

MinSpareServers 5

MaxSpareServers 10

MaxClients 150

MaxRequestsPerChild 0

工作模式为worker模式,编译时已指定为worker模式。

StartServers 2

MaxClients 150

MinSpareThreads 25

MaxSpareThreads 75

ThreadsPerChild 25

MaxRequestsPerChild 0

2、 httpd-vhosts.conf 配置网站大部分在这里配置

NameVirtualHost *:80 基于域名的服务,一个主机想跑多个网站在这里配置

3、httpd-default.conf 了解

Timeout 300 超时

KeepAlive On 连接保持

MaxKeepAliveRequests 100 最大接受多少个连接

KeepAliveTimeout 5 等待下一个连接时间

AccessFileName .htaccess 设置伪静态

ServerTokens Full 隐藏apache版本

ServerSignature On 隐藏apache版本

FQDN 完整的域名解析

错误报告:httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Syntax OK

解决办法: vim /usr/local/apache/conf/httpd.conf

把 servername www.example.com:80 增加成servername 127.0.0.1:80

Cache-Control是http协议1.1中支持的缓存字段,指定请求和响应遵循的缓存机制。

详见rfc2616 14.9(Cache-Control)

其中一个最基础的策略是,在响应头中设定:

Cache-control: max-age=[secs]

[secs]是cache在客户端存活的秒数,例如 Cache-control: max-age=1800 表明cache的时间是半小时,只使用这样一个声明就可以使浏览器能够将这个HTTP响应的内容写入临时目录做cache。当用户第二次请求被缓存的资源时,浏览器将直接给出响应,不再从服务器请求,直到cache过期。

二.如何通过apache实现max-age的设置

可以通过mod_headers模块,实现max-age的设置

1)确保安装了mod_headers

2)在httpd.conf 中设置LoadModule headers_module modules/mod_headers.so

3)使用例子

<IfModule mod_headers.c>

# htm,html,txt类的文件缓存一个小时

<filesmatch "\.(html|htm|txt)$">

header set cache-control "max-age=3600"

</filesmatch>

# css, js, swf类的文件缓存一个星期

<filesmatch "\.(css|js|swf)$">

header set cache-control "max-age=604800"

</filesmatch>

</IfModule>

其实mod_headers的功能远强大于此,它可以设置http请求头的任一字段,如果你的请求头和足够了解,可以通过mod_headers实现更多缓存策略。转载,仅供参考。

1、我的是apache 2.2.3版本,请注意你的apache版本,一般2.2.x都可以。

    2、开启mod_encoding支持,需要开启mod_headers模块

         vi httpd.conf修改(该模块的安装不做介绍另请查阅,我的apache自带):

         LoadModule headers_module modules/mod_headers.so

    3、在安装mod_encoding RPM包时会自动生成 /etc/httpd/conf.d/mod_encoding.conf

    4、要完美支持中文还需修改配置文件内容为:

LoadModule encoding_module modules/mod_encoding.so

<IfModule mod_headers.c>

    Header add MS-Author-Via "DAV"

</IfModule>

<IfModule mod_encoding.c>

    EncodingEngine on

    NormalizeUsername on

    SetServerEncoding GBK

    DefaultClientEncoding UTF-8 GBK GB2312

    AddClientEncoding "(Microsoft .* DAV $)" UTF-8 GBK GB2312

    AddClientEncoding "Microsoft .* DAV" UTF-8 GBK GB2312

    AddClientEncoding "Microsoft-WebDAV*" UTF-8 GBK GB2312

</IfModule>

5、修改完毕


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/7905230.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存