標籤:
CentOS Apache httpd ConfigNote
一、安裝Apache程式,一般有三種安裝方式:
1.直接網路安裝;
yum install -y httpd
2.下載rpm包,上傳至伺服器進行安裝;
rpm -qa | grep httpd
------------------------------
啟動/停止/重新啟動/狀態
service httpd start
service httpd stop
service httpd restart
service httpd status
pstree | grep httpd //驗證服務是否啟動,比較少用;
啟動時,如果提示如下資訊:
正在啟動 httpd:httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain for ServerName
編輯/etc/httpd/conf/httpd.conf
找到如下內容:
#ServerName www.example.com:80
更改為
ServerName localhost:80
再重啟一下Apache服務即可;
------------------------------
測試安裝配置是否成功
http://ip地址
如果出來:Apache 2 Test Page powered by CentOS 說明就OK了,簡單吧;
如果打不開,那應該是iptables的問題;
編輯/etc/sysconfig/iptables
添加如下內容:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
然後重啟一下iptables服務可;
------------------------------
二基本配置:
1.針對主機環境的設定項目
編輯/etc/httpd/conf/httpd.conf
KeepAlive off
更改為
KeepAlive on
MaxKeepAliveRequests 100
更改為
MaxKeepAliveRequests 500 //為了增進效率則可以改大一點;
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
StartServers 4
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
兩個執行模組,預設使用prefork模組,如果想使用worker模組編輯如下檔案:
/etc/sysconfig/httpd
找下如下內容:
#HTTPD=/usr/sbin/httpd.worker
更改為
HTTPD=/usr/sbin/httpd.worker
然後重啟一下apache服務即可;
------------------------------
2.針對中文Big5編碼語言
編輯/etc/httpd/conf/httpd.conf
找到如下內容:
AddDefaultCharset UTF-8
更改為
#AddDefaultCharset UTF-8
或者
AddDefaultCharset gb2313 //根據實際情況設定;
找到如下內容:
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
更改為
LanguagePriority zh-CN en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-TW
然後重啟一下apache服務即可;
------------------------------
3.針對首頁許可權相關設定
編輯/etc/httpd/conf/httpd.conf
找到如下內容:
Options Indexes FollowSymLinks
更改為
Options FollowSymLinks MultiViews
然後重啟一下apache服務即可;
------------------------------
4.設定開機自動啟動
chkconfig httpd on
------------------------------
CentOS Apache伺服器安裝與配置