Apache 安装及常用参数设置

  1. 禁用 selinux

    setenforce 0

    sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

    sed -i "s/SELINUXTYPE=targeted/#SELINUXTYPE=targeted/g" /etc/selinux/config

  2. 安装 apache

    yum -y install httpd php

  3. 更改 apache 参数

    a. 修改 ServerLimit 默认为 256

    b. 修改 MaxClients 默认为 256

    根据服务器性能做相应调整。下载服务器一般调到 1024 或更大

    且值 ServerLimit >=MaxCliens

    sed -i "s/256/1024/g" `grep 256 -rl /etc/httpd/conf/httpd.conf`

    c. 取消 #ServerNamewww.example.com:80 的注释

    sed -i "s/#ServerName www.example.com:80/ServerName www.example.com:80/g" /etc/httpd/conf/httpd.conf

    d. 修改 OptionsIndexes FollowSymLinks —> Options FollowSymLinks 禁止显示 Apache 目录列表

    sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/g" /etc/httpd/conf/httpd.conf

    e. 修改 AllowOverride 参数 None —>All   .htaccess 文件将启用

    sed-i "s/AllowOverride None/AllowOverride All/g"  /etc/httpd/conf/httpd.conf

    f. 一个持久链接中允许的最大请求数量

    sed -i "s/MaxKeepAliveRequests 100/MaxKeepAliveRequests 500/g"  /etc/httpd/conf/httpd.conf

  4. 添加 vhost 文件

    <VirtualHost*:80>  
         ServerAdmin webmaster@youwebsite.com  
         ServerName youwebsite.com  
         ServerAlias www.youwebsite.com *.youwebsite.com serverIP
         DocumentRoot /home/youwebsite.com/public_html/  
         ErrorLog /home/youwebsite.com/logs/error.log  
         # LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %{cookie}n" usertracklog
         # CustomLog /home/youwebsite.com/logs/access.log combined usertracklog
         CustomLog /home/youwebsite.com/logs/access.log combined 
    </VirtualHost>  
    Vhost Code
  5. 创建网站目录

    mkdir–p /home/youwebsite.com/public_html/

    mkdir/home/youwebsite.com/logs/

  6. 设置 apache 开机启动,重启 apache

    chkconfig–levels 235 httpd on

    service httpd restart

  7. 自定义 apache 日志

    修改 httpd.conf 文件中的 LogFormat 即可。但是 LogFormat 无法剔除日志

    使用 SetEnvIf 参数可以剔除日志

    (可以根据请求主机名 Remote_Addr、Request_Method 的 get 或者 post 请求、Request_URI 请求的文件名或浏览器语言 Accept-Language 做分离)

    例子:不记录 172.16.193.1 的访问日志

    SetEnvIf Remote_Addr "172.16.193.1" dontlog

    Customlog /home/test.com/logs/nolocal.log common env=!dontlog

原文地址:https://www.cnblogs.com/Mrhuangrui/p/4556456.html