Loading

Linux之apache

apache编译参数及解释

yum -y install  openssl openssl-devel zlib zlib-devel

 

./configure \
--prefix=/usr/local/apache2.2  \
--enable-so \
--with-mpm=worker \
--enable-deflate \
--enable-headers \
--enable-rewrite \
--enable-expires \
--enable-cache \
--enable-mem-cache \--enable-module=so \
--enable-proxy \
--enable-proxy-connect \
--enable-proxy-http \
--enable-proxy-balancer \
--enable-proxy-ajp \
--enable-http \
--enable-ssl \
--enable-rule=SHARED_CORE \
&& make && make install
configure   //配置源代码树
–prefix=/usr/local/apache2.2   //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
–enable-module=so   //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
–enable-deflate=shared   //支持网页压缩
–enable-expires=shared   //支持 HTTP 控制
–enable-rewrite=shared   //支持 URL 重写
–enable-cache //支持缓存
–enable-file-cache //支持文件缓存
–enable-mem-cache //支持记忆缓存
–enable-disk-cache //支持磁盘缓存
–enable-static-support   //支持静态连接(默认为动态连接)
–enable-static-htpasswd   //使用静态连接编译 htpasswd – 管理用于基本认证的用户文件
–enable-static-htdigest   //使用静态连接编译 htdigest – 管理用于摘要认证的用户文件
–enable-static-rotatelogs   //使用静态连接编译 rotatelogs – 滚动 Apache 日志的管道日志程序
–enable-static-logresolve   //使用静态连接编译 logresolve – 解析 Apache 日志中的IP地址为主机名
–enable-static-htdbm   //使用静态连接编译 htdbm – 操作 DBM 密码数据库
–enable-static-ab   //使用静态连接编译 ab – Apache HTTP 服务器性能测试工具
–enable-static-checkgid   //使用静态连接编译 checkgid
–disable-cgid   //禁止用一个外部 CGI 守护进程执行CGI脚本
–disable-cgi   //禁止编译 CGI 版本的 PHP
–disable-userdir   //禁止用户从自己的主目录中提供页面
–with-mpm=worker // 让apache以worker方式运行,默认是prefork模式。
–enable-authn-dbm=shared // 对动态数据库进行操作。Rewrite时需要。

查看上一次的编译参数,如果上次安装后没有make clean的话,在config.nice中可以找到

cat /usr/local/apache/build/config.nice

设定文件的根目录

DocumentRoot "/usr/local/apache2.2/htdocs"

设定目录的权限

<Directory /usr/local/apache2.2/web>
    Options -Indexes FollowSymLinks    //Indexes的作用是缺省指定首页文件文件的情况下会展示目录下的所有目录或文件,一般情况是去掉或者加—
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

指定首页文件

<IfModule dir_module>
    #DirectoryIndex index.html
    DirectoryIndex  test.html index.html
</IfModule>

配置虚拟主机

注意要监听8000;并且配置好<Directory /var/html/>

NameVirtualHost *:80
#####基于域名
<VirtualHost *:80>
    ServerAdmin zy5724@163.com
    DocumentRoot "/var/html/www"
    ServerName www.zydev.com
    ErrorLog "logs/www-error_log"
    CustomLog "logs/www-access_log" common
</VirtualHost>

####基于端口
<VirtualHost *:8000>
    ServerAdmin zy5724@163.com
    DocumentRoot "/var/html/bbs"
    ServerName bbs.zydev.com
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common
</VirtualHost>

#########基于Ip
<VirtualHost 192.168.1.142:80>
    ServerAdmin zy5724@163.com
    DocumentRoot "/var/html/blog"
    ServerName www.zydev.com
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common
</VirtualHost>

 Apache的日志

使用cronolog或者Apache自带的日志轮询工具(不建议使用)进行日志轮询

</VirtualHost>
    DocumentRoot "/var/html/www"
    ServerName www.zydev.com
    ErrorLog "logs/www-error_log"
    #CustomLog "logs/www-access_log" common
    CustomLog "|/usr/local/sbin/cronolog /usr/local/apache/logs/www-access_%Y%m%d.log" common
</VirtualHost>
apachelog中找出访问次数最多的10个IP。
awk '{print $1}' apache_log |sort |uniq -c|sort -nr|head -n 10

mod_expires DSO的安装方法

cd  /usr/local/src/httpd-2.2.31/modules/metadata/
/usr/local/apache/bin/apxs -c -i -a mod_expires.c
ll /usr/local/apache/moduls/mod_expires.c

 mod_expires的使用,

<VirtualHost *:8000>
    ServerAdmin zy5724@163.com
    DocumentRoot "/var/html/bbs"
    ServerName bbs.zydev.com
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" combined
        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 plus 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"
</VirtualHost>

其结果可使用curl -I  http://bbs.zydev.com:8000查看

[root@nagiosServer bbs]$ curl -I  http://bbs.zydev.com:8000
HTTP/1.1 200 OK
Date: Sun, 14 Feb 2016 21:10:43 GMT
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/1.0.1e-fips
Last-Modified: Sun, 14 Feb 2016 20:07:16 GMT
ETag: "402a7-e-52bc0726c0f9b"
Accept-Ranges: bytes
Content-Length: 14
Cache-Control: max-age=31104000
Expires: Wed, 08 Feb 2017 21:10:43 GMT
Content-Type: text/html

ps:以上的操作会在“地址栏输入地址回车或者超链接跳转”时,expire的设置会起到作用,此时会读取本地缓存,不会向服务器再次发送请求。

mode_deflate模块的使用

<ifmodule mod_deflate.c>
            DeflateCompressionLevel 9             //1-9 压缩的越高,占用的CPU用越多                                   
            SetOutputFilter DEFLATE
            AddOutputFilterByType DEFLATE text/html text/plain text/xml
            AddOutputFilterByType DEFLATE application/javascript
            AddOutputFilterByType DEFLATE text/css
             </ifmodule>

 

posted @ 2016-02-14 11:20  头痛不头痛  阅读(549)  评论(0编辑  收藏  举报