Apache配置

一、Apache配置

   cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.confbak110820 修改之前先备份原文件

   cp /etc/httpd/conf/httpd.confbak110820 /etc/httpd/conf/httpd.conf 恢复备份文件

   vi /etc/httpd/conf/httpd.conf 编辑文件

============================================================================================================


   ServerTokens OS  ← 找到这一行,将“OS”改为“Prod”(在出现错误页的时候不显示服务器操作系统的名称)

   ServerTokens ProductOnly   ← 变为此状态


   ServerSignature On  ← 找到这一行,将“On”改为“Off”

   ServerSignature Off  ← 在错误页中不显示Apache的版本


   Options Indexes FollowSymLinks  ← 找到这一行,删除“Indexes”,并添加“Includes”、“ExecCGI”,禁止列出目录

   Options Includes ExecCGI FollowSymLinks  ← 允许服务器执行CGI及SSI


   AddHandler cgi-script .cgi  ← 找到这一行,去掉行首的“#”,并在行尾添加“.pl”

   AddHandler cgi-script .cgi .pl  ← 允许扩展名为.pl的CGI脚本运行


   AllowOverride None  ← 找到这一行,将“None”改为“All”

   AllowOverride All  ← 变为此状态,允许.htaccess


   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  ← 找到这一行

   LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  ← 改为此状态(添加“!414”到规则中,对于过长的日志不记录)


   AddDefaultCharset UTF-8  ← 修改UTF-8为GB2312

   AddDefaultCharset GB2312  ← (添加GB2312为默认编码)


  Options Indexes MultiViews FollowSymLinks  ← 找到这一行,将“Indexes”删除

  Options MultiViews FollowSymLinks  ← 变为此状态(不在浏览器上显示树状目录结构)


   DirectoryIndex index.html index.html.var ← 找到这一行,修改默认首页文件

   DirectoryIndex index.html index.htm Default.html Default.htm index.php Default.php index.html.var ← 变为此状态(设置默认首页文件,增加index.php)


   KeepAlive Off #修改为On 允许程序性联机

   KeepAlive On


   MaxKeepAliveRequests 100 #修改为1000 一次联机最大传输数量,0为不限制

   MaxKeepAliveRequests 500

=======================================================================================================================================================  

   /etc/init.d/httpd restart 重启

   rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html 删除默认测试页


====================================================================================

Apache配置虚拟主机

新建虚拟主机配置文件

vi /etc/httpd/conf.d/vhost.conf

====================================


NameVirtualHost *:80

<Directory "/home/wwwroot/web1/htdocs/">

    php_admin_value open_basedir "home/wwwroot/web1/htdocs/:/tmp/" #将该网站PHP访问权限,限制在这个目录。能有效的防止PHP木马跨目录

    Options Includes ExecCGI FollowSymLinks

    AllowOverride All

    Order allow,deny

    Allow from all


</Directory>

<Directory "/home/wwwroot/web2/htdocs/">


    Options Includes ExecCGI FollowSymLinks

    AllowOverride All

    Order allow,deny

    Allow from all


</Directory>

<Directory "/home/wwwroot/web3/htdocs/">


    Options Includes ExecCGI FollowSymLinks

    AllowOverride All

    Order allow,deny

    Allow from all


</Directory>


<VirtualHost *:80>

   # ServerAdmin [email protected]

    DocumentRoot /home/wwwroot/web1/htdocs/

    ServerName www.web1.com

   # ErrorLog logs/dummy-host.example.com-error_log

   # CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>


<VirtualHost *:80>

   # ServerAdmin [email protected]

    DocumentRoot /home/wwwroot/web2/htdocs/

    ServerName www.web2.com

   # ErrorLog logs/dummy-host.example.com-error_log

   # CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>


<VirtualHost *:80>

   # ServerAdmin [email protected]

    DocumentRoot /home/wwwroot/web3/htdocs/

    ServerName www.web3.com

   # ErrorLog logs/dummy-host.example.com-error_log

   # CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>



/etc/init.d/httpd restart 重启 


你可能感兴趣的:(Apache配置)