Apache中有一個mod_proxy模組,開啟後就可以讓Apache有proxy的功能(很吃記憶體)

最常用到的就是用在網頁上

Enable
如果在Ubuntu中可以透過以下指令開啟

1a2enmod proxy_http

在FreeBSD中必須手動開啟以下兩個Module

1LoadModule proxy_module libexec/apache22/mod_proxy.so
2LoadModule proxy_http_module libexec/apache22/mod_proxy_http.so

Forward Proxy
Forward Proxy是一般proxy的代理功能

1Listen 8080
2<VirtualHost *:8080>
3    ServerName proxy.johnsonlu.org
4    #ProxyRequests要開啟,啟動Forward功能
5    ProxyRequests On
6    ProxyVia On
7 
8    <Proxy *>
9        Order deny,allow
10        Deny from all
11        Allow from all
12    </Proxy>
13 
14    ErrorLog "/var/log/apache2/proxy-error.log"
15    CustomLog "/var/log/apache2/proxy-access.log" common
16</VirtualHost>

Reverse Proxy
Reverse Proxy跟Forward Proxy正好相反,可以應用在導向內部實際服務的伺服器

1<VirtualHost *:80>
2    ServerName blog.johnsonlu.org
3    #因為只是Reverse,因此ProxyRequests要關閉
4    ProxyRequests off
5    <Proxy *>
6        Order allow,deny
7        Allow from all
8    </Proxy>
9 
10    ProxyPass / http://localhost:3000/
11    ProxyPassReverse / http://localhost:3000/
12    ProxyPreserveHost on
13</VirtualHost>
Categories: Apache