
我想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>
我必須為每個參數編寫這段程式碼嗎?
不RewriteEngine
。Options
AllowOverride
這些選項由您使用指令轉送請求的「遠端」網路伺服器控制並需要設定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、位置、目錄區塊中的設置,而無需一次又一次複製相同的行。