标题真的说明了一切。我无法让我的域从 site.com
重定向到 http://example.com
但 https://example.com
可以作为以及 https://www.example.com
。
我的 nginx conf 如下,删除了敏感路径。这是我所有 nginx 设置的 GIST 链接,它是我整个 nginx configuration 中目前唯一启用的域。 .
本地与服务器上的控制台输出:
rublev@rublevs-MacBook-Pro ~
• curl -I rublev.io
^C
rublev@rublevs-MacBook-Pro ~
• ssh r
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-75-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
78 packages can be updated.
0 updates are security updates.
Last login: Fri May 12 16:41:35 2017 from 198.84.225.249
rublev@ubuntu-512mb-tor1-01:~$ curl -I rublev.io
HTTP/1.1 200 OK
Server: nginx/1.10.0 (Ubuntu)
Date: Fri, 12 May 2017 16:41:43 GMT
Content-Type: text/html
Content-Length: 339
Last-Modified: Thu, 20 Apr 2017 20:47:12 GMT
Connection: keep-alive
ETag: "58f91e50-153"
Accept-Ranges: bytes
我束手无策,我真的不知道现在该做什么,我花了数周时间试图让它发挥作用。
最佳答案
LetsEncrypt 默认使用 http,为了安全起见,最好保留它访问 well-known
的能力以应对 acme 挑战。您似乎也没有指向正确的路径,除非您将 webroot 更改为 /home/rublev/sites/rublev.io
?
我会尝试像这样重写您的默认服务器,而不是直接重定向到您的 https
等价物。此外,它可以让您更轻松地测试这种奇怪的行为。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name rublev.io www.rublev.io;
location / {
return 301 https://$server_name$request_uri;
}
location ~ /.well-known {
# Apparently you changed your webroot,
# just make sure that the file is created and accessible
root /home/rublev/sites/rublev.io/.well-known;
}
}
此外,了解您需要两个不同的证书或一个接受您的域的证书(无论是否有 www
形式)也很重要。如果不是这种情况,那很可能就是您出现问题的原因。要生成包含两个域的证书,您可以运行以下命令:
sudo ./certbot-auto certonly --standalone -d rublev.io -d www.rublev.io --dry-run
我还会注释掉您的 jenkins 服务器和配置,以防万一它弄乱了您的主要服务器。注:来自this question ,您可以使用 proxy_redirect http://$scheme://;
而不是您当前正在使用的表单。它不应该影响另一台服务器,但我更愿意在这些奇怪的情况下确定。
另一件事,可能是通往另一种解决方案的途径,是考虑只选择一种形式的域(有或没有 www
),并将用户从“错误”重定向到正确的那一个。这将使您获得更一致的 URL,更利于 SEO 和共享您的链接的人。
关于http - 如何将裸域 "example.com"重定向到 "https://example.com"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43882712/