Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

源碼安裝 Apache 並設定反向代理轉發

本文示範如何以源碼方式安裝 Apache,並設定反向代理轉發功能。

一、編譯安裝 Apache

a) 解壓:tar -xvf httpd-*

b) 設定編譯參數:

./configure --prefix=/usr/oracle/apache CC="gcc -m32" \
--enable-proxy=shared --enable-proxy-http=shared --enable-proxy-ftp=shared --enable-proxy-connect=shared --enable-so --enable-modules=all --enable-mods-shared=all

c) make;d) make install

基本操作指令

以下假設安裝於 /usr/local/apache2。啟動:/usr/local/apache2/bin/apachectl start;停止:apachectl stop;重啟:apachectl restart。若不希望重啟時中斷現有連線,可執行 /usr/local/sbin/apachectl graceful。

若已註冊為系統服務,可用 service httpd start|restart|stop 操作。

設定轉發功能

開啟安裝目錄下 conf 資料夾的 httpd.conf:

1、移除以下兩行前的註解符號 #:

#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_http_module modules/mod_proxy_http.so

2、在檔案末尾加上轉發規則。例如將以 /cas 開頭的請求轉發到 206 伺服器 9090 埠:

ProxyPass /cas https://192.168.0.206:9090/cas
ProxyPassReverse /cas https://192.168.0.206:9090/cas

其他轉發依此類推。若某路徑不需轉發而交由 Apache 自行處理(如 /bbs),則以驚嘆號排除:

ProxyPass /bbs !
ProxyPassReverse /bbs !

Copyright © Linux教程網 All Rights Reserved