V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
qinrui
V2EX  ›  正则表达式

求助 nginx 的 rewrite,需求是把 http 流量转到 https

  •  
  •   qinrui · 2022-11-14 22:40:57 +08:00 · 1127 次点击
    这是一个创建于 527 天前的主题,其中的信息可能已经有所发展或是发生改变。

    网上搜到这样一句:

    	rewrite ^(.*)$  https://$host$1 permanent;
    

    但是出现了循环重定向

    因为用的是 xinnet 的虚拟主机,rewrite 不能指定写在 80 端口下,所以导致 https 也重定向

    哪位大佬能帮忙写一个,判断 scheme 是 http://时,重定向到 https://

    5 条回复    2022-11-14 23:28:34 +08:00
    clickhouse
        1
    clickhouse  
       2022-11-14 22:46:22 +08:00
    Yourshell
        2
    Yourshell  
       2022-11-14 22:55:17 +08:00
    qinrui
        3
    qinrui  
    OP
       2022-11-14 22:57:44 +08:00
    @clickhouse
    @Yourshell
    谢谢两位,但受限于 xinnet 的虚拟主机的功能,我只能写一句 rewrite 开头的命令,而且不能指定是在 80 下,还是 443 下,所以两位给的方法不适用
    adoal
        4
    adoal  
       2022-11-14 23:28:19 +08:00
    既然是这个垃圾 xinnet 的沙雕限制,那就去问它家客服呗。网友又不能突破这种人为的沙雕限制。
    qinrui
        5
    qinrui  
    OP
       2022-11-14 23:28:34 +08:00
    想到解决办法了,在 php 里加了$_SERVER 的判定
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1010 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:25 · PVG 04:25 · LAX 13:25 · JFK 16:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.