將 ip 重定向到 apache 上的網域(wordpress by bitnami)

將 ip 重定向到 apache 上的網域(wordpress by bitnami)

我剛剛使用 bitnami 在 aws 上創建了一個 WordPress 網站,並將其指向我的網域。問題是該網站可以透過 IP 和網域存取。如何將 IP 重新導向到網域?

答案1

建立預設 VirtualHost(請參閱https://httpd.apache.org/docs/2.4/vhosts/details.html)回應任何不合格的主機名稱(和裸 IP 位址)和第二個 VirtualHost,只有在使用您所需的主機名稱/網域時才能存取。將預設 VirtualHost 重定向(在 http 層級)到您的網域。

<VirtualHost *:80>
    ServerName default
    Redirect "/" "http://www.example.com/"
</VirtualHost>

<VirtualHost *:80>
    ServerName www.example.com
    #  enter other directives here

</VirtualHost>

相關內容