V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
qinrui

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

  •  
  •   qinrui · Nov 14, 2022 · 1831 views
    This topic created in 1269 days ago, the information mentioned may be changed or developed.

    网上搜到这样一句:

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

    但是出现了循环重定向

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

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

    5 replies    2022-11-14 23:28:34 +08:00
    clickhouse
        1
    clickhouse  
       Nov 14, 2022
    Yourshell
        2
    Yourshell  
       Nov 14, 2022
    qinrui
        3
    qinrui  
    OP
       Nov 14, 2022
    @clickhouse
    @Yourshell
    谢谢两位,但受限于 xinnet 的虚拟主机的功能,我只能写一句 rewrite 开头的命令,而且不能指定是在 80 下,还是 443 下,所以两位给的方法不适用
    adoal
        4
    adoal  
       Nov 14, 2022
    既然是这个垃圾 xinnet 的沙雕限制,那就去问它家客服呗。网友又不能突破这种人为的沙雕限制。
    qinrui
        5
    qinrui  
    OP
       Nov 14, 2022
    想到解决办法了,在 php 里加了$_SERVER 的判定
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3486 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 11:44 · PVG 19:44 · LAX 04:44 · JFK 07:44
    ♥ Do have faith in what you're doing.