简体   繁体   English

是否可以使用 nginx 将 HTTPS 重定向到 HTTPS?

[英]Is it possible to redirect HTTPS to HTTPS with nginx?

I have the following issue.我有以下问题。 I created this danish website flaatinfo.dk that is also accessible by flåtinfo.dk.我创建了这个丹麦网站 flaatinfo.dk,flåtinfo.dk 也可以访问它。

The domain manager gave me a certificate for flaatinfo.dk but said that they could not generate one for flåtinfo.dk because it contains a special character.域管理员给了我一个 flaatinfo.dk 的证书,但说他们无法为 flåtinfo.dk 生成一个证书,因为它包含一个特殊字符。

Is there a way (in nginx setup) that I can redirect all HTTPS requests from flåtinfo.dk to flaatinfo.dk??有没有办法(在 nginx 设置中)我可以将所有 HTTPS 请求从 flåtinfo.dk 重定向到 flaatinfo.dk?

HTTP redirects seem to work fine but if I try to redirect HTTPS like this I get cert error in browser: HTTP 重定向似乎工作正常,但如果我尝试像这样重定向 HTTPS,我会在浏览器中收到证书错误:

server {
    listen 443 ssl;
    server_name flåtinfo.dk www.flåtinfo.dk;
    return 301 https://flaatinfo.dk$request_uri;
}

www.flåtinfo.dk is an internationalized domain name (IDN). www.flåtinfo.dk是一个国际化域名 (IDN)。

According to NGINX documentation for internationalized names :根据国际化名称的 NGINX 文档

domain names (IDNs) should be specified using an ASCII (Punycode) representation in the server_name directive应在server_name指令中使用 ASCII (Punycode) 表示来指定域名 (IDN)

So you should specify it in NGINX configuration as xn--fltinfo-fxa.dk .因此,您应该在 NGINX 配置中将其指定为xn--fltinfo-fxa.dk

As for why your plain HTTP redirect worked anyway, it's probably because it didn't match any other domain so NGINX had to eventually choose it as default.至于为什么你的普通 HTTP 重定向仍然有效,可能是因为它不匹配任何其他域,所以 NGINX 最终不得不选择它作为默认值。

I get cert error in browser我在浏览器中收到证书错误

Naturally, since you don't have a TLS certificate for your IDN, browsers will issue warnings.自然,由于您的 IDN 没有 TLS 证书,浏览器会发出警告。 You need to get a TLS certificate for IDN to get rid of the warning.您需要获得 IDN 的 TLS 证书才能消除警告。 Let's Encrypt supports issuing certs for IDNs and is free of charge. Let's Encrypt 支持为 IDN 颁发证书并且是免费的。

在根位置的.htaccess文件中添加重定向规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM