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

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

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

a2enmod proxy_http

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

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

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

Listen 8080
<VirtualHost *:8080>
    ServerName proxy.johnsonlu.org
    #ProxyRequests要開啟,啟動Forward功能
    ProxyRequests On
    ProxyVia On

    <Proxy *>
        Order deny,allow
        Deny from all
        Allow from all
    </Proxy>

    ErrorLog "/var/log/apache2/proxy-error.log"
    CustomLog "/var/log/apache2/proxy-access.log" common
</VirtualHost>

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

<VirtualHost *:80>
    ServerName blog.johnsonlu.org
    #因為只是Reverse,因此ProxyRequests要關閉
    ProxyRequests off
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>

    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
    ProxyPreserveHost on
</VirtualHost>
Categories: Apache