編譯安裝httpd後利用指令碼修改參數

來源:互聯網
上載者:User

標籤: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後利用指令碼修改參數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.