安裝apache:
官網:http://httpd.apache.org/download.cgi#apache24
1.wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.gz
2.tar zxvf httpd-2.4.10.tar.gz
3.cd httpd-2.4.10 && ./configure ... && make && make install
**報錯APR not found,解決辦法(安裝apache2.2.22版本沒有問題,2.4才會有這個問題)
=======================================
1.下載下傳所需軟體包:
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
具體步驟如下:
a:解決apr not found問題>>>>>>
[root@xt test]# tar -zxf apr-1.4.5.tar.gz
[root@xt test]# cd apr-1.4.5
[root@xt apr-1.4.5]# ./configure --prefix=/usr/local/apr
[root@xt apr-1.4.5]# make && make install
b:解決APR-util not found問題>>>>
[root@xt test]# tar -zxf apr-util-1.3.12.tar.gz
[root@xt test]# cd apr-util-1.3.12
[root@xt apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with- apr=/usr/local/apr
[root@xt apr-util-1.3.12]# make && make install
c:解決pcre問題>>>>>>>>>
[root@xt test]#unzip -o pcre-8.10.zip
[root@xt test]#cd pcre-8.10
[root@xt pcre-8.10]#./configure --prefix=/usr/local/pcre
[root@xt pcre-8.10]#make && make install
2.最後編譯Apache時加上:
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--with-pcre=/usr/local/pcre
4.重新編譯安裝:./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite
5.make && make install
安裝完成後配置配置檔案:
修改ServerName localhost.localdomain (可通過hostname檢視本機servername)
開啟Include conf/extra/httpd-mpm.conf(配置prefork模式的選項,下邊有介紹)
開啟Include conf/extra/httpd-default.conf (下邊有介紹)
Apache源碼包安裝的子配置檔案介紹:
配置檔案位置:/usr/local/apache2/etc/httpd.conf
子配置檔案: /usr/local/apache2/etc/extra/*.conf
源碼包安裝的Apache的配置檔案并不是在一個檔案裡,主配置檔案裡邊隻有400多行,裡邊加載了extra子配置檔案,但預設都是注釋的。
常用子配置檔案介紹:
====================
1.httpd-autoindex.conf #apache系統别名,設定别名目錄在此配置檔案中設定。
Alias /icons/ "/usr/local/apache2//icons/" #通過www.domain.com/icons/通路
<Directory "/usr/local/apache2//icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /soft/ "/www/soft/" #通過www.domain.com/soft通路
<Directory "/www/soft/">
tips:别名目錄不一定在apache根目錄下,在任意目錄下都可以,能夠跳出網站主目錄的限制,直接通.過www.domain.com/alias/通路。指定的别名目錄下邊一定要指定目錄權限,即<Directory>。别名目錄中 / 不能省略。
2.httpd-default.conf #apache線程控制,必須開啟。
Timeout 300 #逾時時間
KeepAlive On #開啟線程控制(不開啟的話使用者通路頁面會産生一個程序,通路其他頁面會産生另一個程序,這樣的話一個使用者會産生好多個程序,會降低apache性能。開啟此項,當使用者通路網站時會産生一個程序,打開其他頁面時會産生線程,保證了一個使用者隻産生一個程序。網站此項功能必須開啟。)
MaxKeepAliveRequests 100 #最大線程連接配接數
3.httpd-info.conf #apache狀态統計
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .example.com
</Location>
通過通路www.domain.com/server-status可以檢視apache狀态。如果頁面顯示not found 則需要修改目錄權限,在Deny from all下加上allow from ip(允許的ip)。
4.httpd-manual.conf #apache幫助文檔
通過通路www.domain.com/manual 檢視apache幫助文檔,一般為英文,沒用,可以到apache官網下載下傳幫助文檔。
5.httpd-languages.conf #語言編碼
要使其生效需要在主配置檔案中打開,如果中文亂碼不是浏覽器編碼的原因可能是此配置檔案注釋沒打開。
6.httpd-mpm.conf #最大用戶端限制
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
MaxClients為最大用戶端數量,即程序數。裡邊有兩個上邊的<IFModule>預設mpm_worker_module生效。
最大用戶端數量由伺服器性能決定,可通過top指令檢視目前狀态,進行調整。
7.httpd-multilang-errordoc.conf #報錯頁面
ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
可以到對應的頁面下修改顯示的報錯頁面。
7.其他:
httpd-ssl.confssl #安全套接字通路 沒講,不用研究。
httpd-userdir.conf #使用者主目錄配置 用的不多,不講。
httpd-vhosts.conf虛拟主機,單獨介紹。