Apache2

在 Apache2 中使用別名繞過位置

  • May 28, 2017

我想知道如何使用 Apache 作為特定路徑的反向代理,以及作為其子路徑的本地伺服器。

對於特定位置,我使用 Apache 作為反向代理 ( https://my.server.com/my-tools):

<Location /my-tools>
   Order allow,deny
   Allow from all
   ProxyPass http://10.1.1.11:3101/my-tools
   ProxyPassReverse http://10.1.1.11:3101/my-tools
</Location>

問題是我想使用本地伺服器(https://my.server.com/my-tools/images/)來評估它。我嘗試添加別名但沒有成功:

Alias /my-tools/images/ /home/myself/public/images/
<Directory /home/myself/public/images/>
   Order allow,deny
   Allow from all
</Directory>

我也嘗試添加它,但它也不起作用:

<Location /my-tools/images/>
   SetHandler None
</Location>

https://my.server.com/my-tools/images/myimage.png例如,當我輸入時,它會不斷重定向到遠端伺服器。

mod_proxyProxyPass文件中有一個直接的例子:

!指令在您不想反向代理子目錄的情況下很有用,例如

<Location "/mirror/foo/">
    ProxyPass "http://backend.example.com/"
</Location>
<Location "/mirror/foo/i">
    ProxyPass "!"
</Location>

在您的情況下,這將是:

<Location "/my-tools/images">
   ProxyPass "!"
   Alias "/home/myself/public/images"
</Location>
<Location "/my-tools/">
   ProxyPass http://10.1.1.11:3101/my-tools/
   ProxyPassReverse http://10.1.1.11:3101/my-tools/
</Location>

或使用替代語法:

ProxyPass "/my-tools/images" "!"
Alias "/my-tools/images" "/home/myself/public/images"
ProxyPass "/my-tools/" "http://10.1.1.11:3101/my-tools/"
ProxyPassReverse "/my-tools/" "http://10.1.1.11:3101/my-tools/"

引用自:https://serverfault.com/questions/852452