每次安装完httpd后,还要改许多参数,很麻烦,于是想到了用脚本自动完成,下面贴出我个人一些指令修改配置.
环境准备:
CentOS6.5 x86_64
httpd-2.4.16
#!/bin/bash
# Author:soy sauce
# Date:2015-09-18 16:28
# Description:configure httpd directives
#1.PidFile增加
sed -i '/^ServerRoot/a \PidFile "/var/run/httpd.pid"' /etc/httpd/httpd.conf
#2.Servername修改
sed -i -r 's@^#(ServerName).*@\1 localhost:80@g' /etc/httpd/httpd.conf
#3.Document修改
sed -r -i 's@^(DocumentRoot).*@\1 "/data/apache"@g' /etc/httpd/httpd.conf
#4.Directory修改
sed -i 's@/usr/local/apache/htdocs@/data/apache@g' /etc/httpd/httpd.conf
#5.添加php支持
sed -r -i "/AddType (.*)[[:space:]].gz/a \ AddType application/x-httpd-php .php" /etc/httpd/httpd.conf
sed -i -r "/[^#]AddType(.*).tgz/a \ AddType application/x-httpd-php-source .phps" /etc/httpd/httpd.conf
#6.修改DirectoryIndex
sed -i "s/DirectoryIndex index.html/DirectoryIndex index.php index.html/g " /etc/httpd/httpd.conf
#7.启用代理和fcig模块(如果httpd使用的fastcgi则启用此项,否则不需要启用)
sed -i -r "s/^#(LoadModule.*proxy_module)/\1/g" /etc/httpd/httpd.conf
sed -i -r "s/^#(LoadModule.*proxy_fcgi)/\1/g" /etc/httpd/httpd.conf
#8.如果要启用虚拟主机(fastcgi机制),则启用vhosts,虚拟主机中添加如下两行,
sed -r 's@^#(Include.*vhosts.conf)@\1@g' /etc/httpd/httpd.conf
echo 'ProxyRequests Off' >> /etc/httpd/extra/httpd-vhosts.conf
echo 'ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/apache/$1' >> /etc/httpd/extra/httpd-vhosts.conf