redirect - 仅 SSL 的 nginx 重写规则

标签 redirect ssl nginx url-rewriting ispconfig

我想将域的所有流量重定向到一个目标: https://example.com 我们想将 http 更改为 https,将 www 更改为非 www。

Nginx 1.8.1 是服务器

这是虚拟主机:

server {
listen xxx.xxx.xxx.xxx:80;
listen xxx.xxx.xxx.xxx:443 ssl;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /www/clients/client1/web2/ssl/example.com.crt;
ssl_certificate_key /www/clients/client1/web2/ssl/example.com.key;

server_name example.com www.example.com;

root   /var/www/example.com/web;
#This is a rewrite from www.example.com  -> example.com
if ($http_host = "www.example.com") {
rewrite ^ $scheme://example.com$request_uri? permanent;
} 

......
......
}                        

我们遇到的问题是,我们检查的每个重定向和重写规则都适用于这三种情况:

https://example.com    -->     is right target        works
http://www.example.com -->     https://example.com  works
http://example.com     -->     https://example.com  works

但是

https://**www**.example.com  ---> https://example.com  don't works 

在浏览器中我们看到 https://www.example.com而不是目标 SSL 域名 https://example.com

在这种情况下,我们的 SL 证书显示“不可信”消息

虚拟主机的配置由 ISPConfig 预设。

有没有人有同样的经历?也许还有一个解决方案。

最佳答案

您的证书很可能仅为 example.com 颁发,对 www.example.com 无效。重定向,就像您在 NGINX 配置中的重定向一样,仅在 TLS/HTTPS 握手之后发生,这是您的浏览器所提示的。

您需要请求您的证书颁发者颁发对 example.com 和 www.example.com 都有效的新证书。大多数发行人一开始就应该这样做,并且不收取任何费用。

关于redirect - 仅 SSL 的 nginx 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35926792/

相关文章:

asp.net-mvc - ASPNET HttpErrors 重定向到 Controller

java - 连接在 Java 8 上被对等方重置,但在 Java 7 上则不然

nginx - "include_recipe"与 Vagrantfile "chef.add_recipe"对比。有什么不同?

configuration - 在 nginx 的配置中, "if (!-f $request_filename) {"是否会导致虚拟机的性能下降?

docker - nginx proxy_pass 导致 404 Not Found 页面

php - PHP表单提交后如何显示成功消息?

javascript - Flask 的重定向(url_for ('profile' ))仅在控制台上加载 HTML,但实际上并不重定向

apache - 如何使.htaccess RewriteRule同时支持path和query_string

java - 获取错误 : PKIX path building failed: unable to find valid certification path to requested target

https - SSL 连接泄露了多少数据?