nginx:将所有内容从http重定向到https,除了一个url-pattern [英] nginx: redirect everything from http to https, except one url-pattern

查看:78
本文介绍了nginx:将所有内容从http重定向到https,除了一个url-pattern的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只能通过HTTPS访问的网站,除了一个URL模式(因为我在某些页面上使用了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆