如何設定Apache重定向到ServerName連接埠?

如何設定Apache重定向到ServerName連接埠?

我剛剛在 Ubuntu 上安裝了 apache2 和 haproxy。 Haproxy 監聽埠 80,apache 監聽 3080,後者對外部是隱藏的。

我的問題是,當使用不帶尾部斜杠的資料夾名稱時,例如example.com/some/folderapache會自動重定向到帶有斜杠的相同地址,但也會重定向到不正確的端口,example.com:3080/some/folder/

Apache 文件向我表明我的問題在於 CanonicalName/Port 配置,但這些的任何組合似乎都不起作用。我可能會誤解什麼?

我的虛擬主機:

<VirtualHost *:3080>

    ServerName http://example.com:80
    UseCanonicalName On
    UseCanonicalPhysicalPort On

    DirectoryIndex index.php index.html
    DocumentRoot /var/www/main

    <Directory /var/www/main>
        Options -Indexes
        Options -FollowSymLinks
        AllowOverride All

        <Files ~'^\.'>
            Order allow,deny
            Deny from all
            Satisfy all
        </Files>
    </Directory>
</VirtualHost>

答案1

兩者都不用;

UseCanonicalName Off
UseCanonicalPhysicalPort Off

HAProxy(通常)不會弄亂發送的Host標頭,因此此配置應該使用正確的Location標頭來建立產生的重定向。如果這沒有幫助,那麼提供Location在回應中發送的確切標頭?

順便說一句,您ServerName可以簡化,並且可能不應該有您的虛擬主機未偵聽的連接埠:

ServerName example.com

相關內容