我剛剛將一個站點轉移到由Forge配置的DO服務器。我安裝了一個SSL證書,注意到導航到https://www.example.com會導致Server Not Found錯誤,而http://example.com返回200.我試圖在Nginx配置文件中強制非WWW,但似乎無法使任何工作。每次嘗試後,我也重新啓動了Nginx。Forge/Nginx DO WWW到非WWW重定向問題
這是我目前Nginx的配置文件:
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name .example.com;
root /home/forge/default/current/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/default/56210/server.crt;
ssl_certificate_key /etc/nginx/ssl/default/56210/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
location/{
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
服務器設置了默認的站點 - 默認,而不是example.com。在啓動網站到生產和安裝SSL證書後,我意識到這一點,我試圖通過在事實後嘗試改變這一點來避免任何停機時間。我不確定這個被稱爲default的網站是否會在這裏有所作爲,但是需要注意的是。
因此,https://或http://example.com工作正常。 www.example.com在我測試過的所有瀏覽器上都會返回「未找到服務器」錯誤。我也注意到,有一個www.default文件/ etc/nginx的/啓用站點-,我試圖將其更改爲以下並重新啓動nginx的:
server {
listen 80;
server_name www.example.com;
return 301 $scheme://example.com/$request_uri;
}
仍然會收到找不到服務器不管是什麼。以下是Chrome上的錯誤:
無法找到www.example.com上的服務器,因爲DNS查找失敗。 DNS是將網站名稱翻譯爲Internet地址的網絡服務。這個錯誤通常是由於沒有連接到Internet或錯誤配置的網絡而導致的。它也可能由無響應的DNS服務器或防火牆阻止Google Chrome訪問網絡引起。