2021年7月14日 星期三

解決 web server 連線出現 The page isn’t redirecting properly 問題

問題點就是出在 Apache 設定檔中

 <VirtualHost *:443>

....

ServerName me.afreeddns.org

....

RewriteCond %{SERVER_NAME} =me.afreeddns.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

因為 ServerName 和 RewriteCond 一樣,

導致 redirect 變成迴圈,

把 RewriteCond 改成和 ServerName 不同就好,例如:

RewriteCond %{SERVER_NAME} =www.me.afreeddns.org

 

錯誤情形在Firefox 就像這樣



因為之前用的免費 Dynamic DNS 服務網站關了,

轉往別的免費 Dynamic DNS 服務網站,

但是好像今年初開始 Certbot 取得 Let's Encrypt 的時候,

如果用 certbot --apache 就會失敗,

只能用 certbot certonly certbot certonly --webroot -w /srv/http -d me.afreeddns.org -d me2.afreeddns.org -w /srv/http2 -d me3.afreeddns.org

就只能產生憑證,不會自動對 apache 設定檔做更改,

所以我自己改的時候,

RewriteCond %{SERVER_NAME} =www.me.afreeddns.org

中的 www被我刪掉,

造成 ServerName 和 RewriteCond 完全相同,

就變成迴圈。

把 RewriteCond 前加上www 就正常了,

以前是為了美化網址加上的,

有發現 certbot --apache 會自動把 RewriteCond RewriteRule 這兩行註解掉。


另外再記件新增網域要做的事,

/etc/hosts 中記得新增 127.0.0.1 new.afreeddns.org

這樣才能在 certbot --apache 時自動出現在選項中

沒有留言:

張貼留言