apache安装

apache2.2下载地址 http://labs.mop.com/apache-mirror/httpd/httpd-2.2.22.tar.gz

卸载本地yum安装的httpd rpm -e --nodeps httpd --nodeps:表示不做软件之间的的依赖检查

for name in `rpm -qa httpd*` ; do rpm -e --nodeps $name ; done

---------------------------------------------------------------------------

编译安装:(编译依赖gcc软件包)

./configure --prefix=/usr/local/apache

--enable-deflate #提供对类容的压缩传输编码支持,一般为html,js,css等站点,此参数会提高传输速度,apache调优重要选项之一

--enable-expires #激活允许通过配置文件控制HTTP的Expires:和Cache-Control:头类容,即对网站图片,js,css等内容提供在客户端浏览器缓存的设置,apache调优重要选项之一

--enable-headers #提供允许对HTTP请求头的控制

--enable-modules=most

--enable-so    # 激活apache服务的DSO(动态共享对象)支持,即在以后以DSO的方式编译安装共享模块,这模块本身不能用DSO方式编译

--with-mpm=worker #worker模式是使用线程来处理请求 所以可以处理更多的并发请求,如果不指定此参数,默认以prefork进程模式, apache调优重要选项之一

--enable-rewrite  #URL重写功能 伪静态通过此模块实现

make

make installma

(方便复制:./configure --prefix=/usr/local/apache --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite )

configure 错误提示:

checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

zlib-devel 没装的原因

-----------------------------------------------------------------------------

/usr/local/apache/apachectl start #启动apache

netstat -lnt 查看80端口是否打开

lsof -i tcp:80 查看80端口是否属于http服务

/usr/local/apache/apachectl graceful 优雅重启

------------------------------------------------------------------------------

mod_Expires 缓存模块

在配置文件里面加上下面这段类容就可以实现缓存

在httpd.conf主配置文件里面配置就对全部虚拟机生效

在虚拟主机配置文件里面 就只对该虚拟机生效 文件夹也可以配置

ExpiresActive on

ExpiresDefault "access plus 12 month"

ExpiresByType text/html "access plus 12 months"

ExpiresByType text/css "access plus 12 months"

ExpiresByType image/gif "access plus 12 months"

ExpiresByType image/jpeg "access plus12 12 months"

ExpiresByType image/jpg "access plus 12 months"

ExpiresByType image/png "access plus 12 months"

EXpiresByType application/x-shockwave-flash "access plus 12 months"

EXpiresByType application/x-javascript "access plus 12 months"

ExpiresByType video/x-flv "access plus 12 months"

DSO模块动态编译:

如果编译安装的时候忘记了编译Expires模块,就需要来DSO动态编译,到httpd源文件压缩包的解压目录/httpd/modules/metadata/目录下

查看有没有mod_expires.c文件 有的话就执行/usr/local/apache/bin/apxs -c -i -a mod_expires.c 进行编译

其他模块 也可以用这方法进行动态编译

用curl -I 域名 来查看是否开启缓存 当出现Expires:的字样 表示开启缓存成功

----------------------------------------------------

mod_deflate 压缩模块

(源模块在解压目录的modules下的filters目录下)

在主配置文件和虚拟主机配置文件都可以

<ifmodule mod_deflate.c>

  DeflateCompressionLevel 9 #压缩级别9

  SetOutputFilter DEFLATE # 打开压缩功能

  AddOutputFilterByType DEFLATE text/html text/plain text/xml #添加压缩类型

 AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE text/css

</ifmodule>

curl -I 域名 信息里面多了Vary 表示已经开启压缩功能了

查看版本号 /usr/local/apache/apachectr -v

一、Apache服务优化: 2

1.配置cronolog进行日志轮询 2

2.错误页面优雅显示 2

3.mod_deflate文件压缩功能 3

4.mod_expires缓存功能 4

5.更改apache的默认用户 5

6.worker模式,提升并发数(可以达到2000-5000) 5

7.屏蔽apache版本等敏感信息 6

8.apache目录文件权限设置(root,目录755,文件644) 6

9.开启httpd-mpm.conf 增加连接数 6

10. apache防盗链功能 8

11.禁止目录Index 8

12. 禁止用户覆盖(重载) 8

13.关闭CGI 9

14.避免使用.htaccess文件(分布式配置文件) 9

15. apache的安全模块 9

16.正确途径取得源代码,勤打apache补丁 10

17.apache日志授予root 700权限 10

18.系统内核参数优化 10

19.禁止PHP解析指定站点的目录 10

20.使用tmpfs文件系统替代频繁访问的目录 11

21尽可能减少 HTTP 请求数 11

22使用CDN做网站加速 12

老男孩老师教的!