
我在 CloudFront 後面的 S3 上有一個現有的靜態 Web 應用程序,比如說example.com
我想添加一個 WordPress 博客,訪問地址為example.com/blog
對於 WordPress 博客,我使用 Apache 和 WordPress 設定了一個 ec2 伺服器。
我已將 ec2 伺服器新增為 CloudFront 中的來源,如所描述的這裡。
當我跑步時:
curl example.com/blog
我越來越:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://ec2-x-x-x-x.us-west-1.compute.amazonaws.com/blog/">here</a>.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at http://ec2-x-x-x-x.us-west-1.compute.amazonaws.com Port 80</address>
</body></html>
因此,我認為我的問題不在於 CloudFront,而是 Apache 伺服器的設定。
我的問題是:如何設定 Apache 以這種方式運作?
意義為子目錄
答案1
當 Apache 知道時,它會告訴瀏覽器 301 Moved Permanently,它會使用ServerName
您在<VirtualHost>
層級或全域層級指定的內容。
如果您沒有設置,ServerName
它會嘗試透過啟發式方法(對 IP 位址之一進行反向 DNS 查詢)來尋找 FQDN,您將獲得典型的悲傷結果。
例子:
ServerName example.com
ServerName http://example.com
ServerName https://example.com:8443