【问题标题】:letsencrypt on nginx and non-www https to www https redirect让我们在 nginx 和非 www https 上加密到 www https 重定向
【发布时间】:2017-06-24 23:43:42
【问题描述】:

我在运行 Nginx 的网络服务器上设置了 Letsencrypt SSL 证书。

http 到 https 重定向对于非 www 和 www 都可以正常工作。 直接去https://www.example.com 工作。 https非www不起作用,浏览器返回连接被拒绝。

所以: http://example.comhttps://www.example.com

http://www.example.comhttps://www.example.com

工作

https://example.comhttps://www.example.com

没用

我的网站配置是

server {
 listen 80;
 server_name example.com www.example.com;
 return 301 https://www.example.com$request_uri;
}

server {
  listen 443 ssl http2;
  server_name example.com;

  #ssl certs locations etc.

  return 301 https://www.example.com$request_uri;
}

server {
  listen 443 ssl http2;
  server_name www.example.com;

  #ssl certs locations etc.

  #rest of main block
}

letsencrypt 证书是使用命令创建的(certbot-auto,因为服务器运行的是较旧的 linux 发行版):

certbot-auto certonly -n -a webroot --webroot-path=[path to webroot] -d example.com -d www.example.com --email foo@example.com --agree-tos

看过其他类似的问题后,nginx conf 应该可以工作。 据我了解,我创建证书的方式意味着 example.com 和 www.example.com 都有一个证书。

当我加载网站并查看证书时,两者都列在主题备用名称下。

【问题讨论】:

    标签: nginx lets-encrypt


    【解决方案1】:

    解决了。原来是DNS设置问题。有一个注册商定制的域转发器,例如从 example.com 到 www.example.com。删除它并为 example.com 添加一条 A 记录修复了所有问题。

    【讨论】:

      猜你喜欢
      • 2018-04-22
      • 1970-01-01
      • 2017-03-10
      • 2014-05-12
      • 2018-06-23
      • 2015-10-23
      相关资源
      最近更新 更多