阿帕契幾個選項的標籤

阿帕契幾個選項的標籤

我想Location在我的 Apache 配置中設定幾個標籤。例如:/image/file/audio將其傳遞給localhost:port/path。現在我用它來/image

 <Location /image>
        RewriteEngine  on
        Options +MultiViews +FollowSymLinks
        AllowOverride All
        ProxyPreserveHost On
        ProxyPass "http://localhost:PORT/image"
        ProxyPassReverse "http://localhost:PORT/image"
    </Location>

我必須為每個參數編寫這段程式碼嗎?或是有什麼捷徑嗎?

謝謝!

答案1

<Location /image>
   RewriteEngine  on
   Options +MultiViews +FollowSymLinks
   AllowOverride All
   ProxyPreserveHost On
   ProxyPass "http://localhost:PORT/image"
   ProxyPassReverse "http://localhost:PORT/image"
</Location>

我必須為每個參數編寫這段程式碼嗎?

RewriteEngineOptionsAllowOverride​這些選項由您使用指令轉送請求的「遠端」網路伺服器控制並需要設定ProxyPass

由於這些指令是無用的,那麼您也不需要 Location 括號來設定它們,並且可以使用內聯ProxyPass無論如何推薦的語法。

這將您的語法減少到僅必要的行:

ProxyPreserveHost On

ProxyPass "/image" "http://localhost:PORT/image"
ProxyPassReverse "/image" "http://localhost:PORT/image"

ProxyPass "/file" "http://localhost:PORT/file"
ProxyPassReverse "/file" "http://localhost:PORT/file"

Apache httpd 確實提供了Include指令來維護單一配置片段,其中包含您想要逐字包含在不同位置、VirtualHost、位置、目錄區塊中的設置,而無需一次又一次複製相同的行。

相關內容