天天看點

編譯安裝httpd後利用腳本修改參數

每次安裝完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