每次安装完httpd后,还要改许多参数,很麻烦,于是想到了用脚本自动完成,下面贴出我个人一些指令修改配置.
环境准备:
CentOS6.5 x86_64
httpd-2.4.16
指令配置
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
如果觉得文件名路径太长,类似那个虚拟主机配置文件名,不想老是重复写,可用!$代替,如果觉得一条条复制麻烦,可创建一个以.sh结尾的文件,再将下面复制好的代码粘贴进去,再赋予执行权限就ok
#!/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
如有错误,请各位大神不吝赐教,谢谢!