V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
declanVox
V2EX  ›  NGINX

客户端访问时, Nginx reverse proxy 强制所有链接 redirect 到 ssl/https 的配置问题

  •  
  •   declanVox · Nov 2, 2014 · 5046 views
    This topic created in 4194 days ago, the information mentioned may be changed or developed.
    http://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom


    return 301 https://$server_name$request_uri;

    return 301 https://$host$request_uri;

    rewrite ^ https://$host$request_uri? permanent;

    以上三种设置均会有一部分 http 的链接(*.tumblr.com, fonts.google.com及.js)被blocked,造成 https 出现混合内容。若 load unsafe scripts(chrome小盾牌),则网页加载完全正常(https提示不信任)。
    请问操作何处失误了?
    9 replies    2015-04-20 23:40:24 +08:00
    ryd994
        1
    ryd994  
       Nov 2, 2014 via Android
    混合内容是指https页面引用了http资源,
    检查一下网页内容,把http资源换掉就行
    letitbesqzr
        3
    letitbesqzr  
       Nov 2, 2014   ❤️ 1
    rewrite ^(.*) https://$host$1 permanent;
    ryd994
        4
    ryd994  
       Nov 2, 2014 via Android   ❤️ 1
    @declanVox 问问题之前自己Google一下啊
    http://nginx.org/en/docs/http/ngx_http_sub_module.html#sub_filter
    附赠一个坑:
    proxy_set_header Accept-Encoding "";
    declanVox
        5
    declanVox  
    OP
       Nov 2, 2014
    @letitbesqzr 依然无改观,只是首页呈混合内容的访问(一直是)
    @ryd994 没打开过 Gzip 压缩,现在有些摸不着头脑了
    declanVox
        6
    declanVox  
    OP
       Nov 2, 2014
    @ryd994 我试了各种 rewrite 和301 >_<,从前天试到今天,实在搞定不定了,诚请支援!
    ryd994
        7
    ryd994  
       Nov 2, 2014 via Android
    @declanVox 代理gzip内容时替换无效,所以
    proxy_set_header Accept-Encoding "";
    declanVox
        8
    declanVox  
    OP
       Nov 3, 2014
    @ryd994 我也加上这条代码了,还是无效!我浪费了4天时间了,无解透了。

    我的 Q 是 四37341149
    xqdoo00o
        9
    xqdoo00o  
       Apr 20, 2015
    请问楼主解决了吗?我也是这个问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5696 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 07:45 · PVG 15:45 · LAX 00:45 · JFK 03:45
    ♥ Do have faith in what you're doing.