標籤:httpd
每次安裝完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 ‘[email protected]^#(ServerName).*@\1 localhost:[email protected]‘ /etc/httpd/httpd.conf
3.Document修改
# sed -r -i ‘[email protected]^(DocumentRoot).*@\1 "/data/apache"@g‘ /etc/httpd/httpd.conf
4.Directory修改
# sed -i ‘[email protected]/usr/local/apache/[email protected]/data/[email protected]‘ /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 ‘[email protected]^#(Include.*vhosts.conf)@\[email protected]‘ /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 ‘[email protected]^#(ServerName).*@\1 localhost:[email protected]‘ /etc/httpd/httpd.conf#3.Document修改 sed -r -i ‘[email protected]^(DocumentRoot).*@\1 "/data/apache"@g‘ /etc/httpd/httpd.conf#4.Directory修改 sed -i ‘[email protected]/usr/local/apache/[email protected]/data/[email protected]‘ /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 ‘[email protected]^#(Include.*vhosts.conf)@\[email protected]‘ /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
如有錯誤,請各位大神不吝賜教,謝謝!
本文出自 “7589461” 部落格,請務必保留此出處http://7599461.blog.51cto.com/7589461/1696111
編譯安裝httpd後利用指令碼修改參數