本文介绍了nginx:将所有内容从 http 重定向到 https,除了一个 url-pattern的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网站,除了一个 URL 模式外,它只能通过 HTTPS 访问(因为我在某些页面上有 http-iframe 并且我想避免安全警告)
I have a website which should only be reachable over HTTPS except one URL-pattern (because I have on some pages http-iframe's and I would like to avoid security warnings)
E.g. this pages should be redirected to https:
http://example.com
http://example.com/a/this-is-an-article
http://example.com/v/this-is-a-video
This pages should not be redirected to https (or should be redirected form https to http)
http://example.com/l/page-with-unsafe-iframe
http://example.com/l/other-page-with-unsafe-iframe
推荐答案
如果 iframe 页面总是在同一个目录中,可以使用简单的前缀位置.
If the iframe pages are always in the same directory, simple prefix locations could be used.
server {
listen 443;
location /l/ { # redirect https iframe requests to http server
return 301 http://$server_name$request_uri;
}
# ...
}
server {
listen 80;
location / { # the default location redirects to https
return 301 https://$server_name$request_uri;
}
location /l/ {} # do not redirect requests for iframe location
# ...
}
这篇关于nginx:将所有内容从 http 重定向到 https,除了一个 url-pattern的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!