redirect - NGINX 将旧的 https 域重定向到新的非 https

标签 redirect ssl nginx

昨天我更改了我的域名帽子是 foobar.tk 并且它运行在 https 上。现在,在我的新域 foobar.eu 上我没有 ssl。

我在不使用 https 时使用 CNAME 记录成功重定向,但不知何故我无法重定向 https://www.example.tkhttp://www.example.eu Chrome 表示连接已重置。 Firefox 表示无法验证内容,...

对于重定向,我使用这些行:

server {
    listen 443; (note: i have tried with *:443, *:443 ssl, 443 ssl)
    server_name www.example.tk; (i have tried with orwithout www.)
    return 301 http://www.example.eu$request_uri; (i have tried to redir to $host also where then cname will handle the issue)
}

什么有效:

http://www.example.tk -> http://www.example.eu使用 CNAME(和所有其他子域)

什么不起作用:

https://www.example.tk -> http://www.example.eu

我仍然可以备份证书,所以如果它能以某种方式帮助我,请告诉我。

谢谢

最佳答案

在 Nginx 上设置 SSL 时,您应该使用 ssl_certificate and ssl_certificate_key directives .

server {
    listen 443 ssl;
    server_name www.example.tk;
    ssl_certificate         /path/to/certificate; #.crt, .cert, .cer, or .pem file
    ssl_certificate_key     /path/to/private/key;
    return 301 http://www.example.eu$request_uri;
}

您可以从您的证书颁发机构获得这两个文件。

你还应该在 listen 指令中添加 ssl 参数。

关于redirect - NGINX 将旧的 https 域重定向到新的非 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35380348/

相关文章:

PHP,重定向到另一个页面

post - 当 POST 从 http 重定向到 https 时,Curl 丢失正文

git - 如何将 zscaler 证书导入 Git

ssl - 获取 "No certificate matches private key"

apache - nginx 将所有域重定向到另一个端口,但为管理应用程序保留一个域

php - 能够在 header() 之前回显

ssl - 如何传递 SSL_CTX 使用的 EC 命名曲线列表?

nginx - 在 Centos 6.8 上升级 nginx

java - {{notification.header}} {{notification.message}} 在访问 Keycloak 管理控制台时加载

Apache 多个 URL 到一个域重定向