如何解决在使用端口映射情况, dsm nginx 跳转到内部端口的问题? - V2EX
moxuanyuan
V2EX    NGINX

如何解决在使用端口映射情况, dsm nginx 跳转到内部端口的问题?

  •  
  •   moxuanyuan May 12, 2020 4685 views
    This topic created in 2191 days ago, the information mentioned may be changed or developed.

    Issue

    众所周知,家宽都没有 80/443 端口,只能在路由中设置端口映射。问题如果 url 尾没加"/",nginx 自动会跳转,例如 https://www.test.com:44311/index 被错误的重定向至https://www.test.com/index/。作为不熟积运维的人,这个问题很头疼,我 google 了很久才找出来。更头疼的是,DSM 作为一个魔改 linux,很多地方会重写配置文件。

    我 google 了很久,都解决不了。我估关键应该是没有找到正确修改 nginx 配置文件的地方

    面是我找到最可能解决的办法,但还是没效。

    ## DSM 6.2 # 创建对应域名的配置文件 # /usr/local/etc/nginx/conf.d/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/user.confg location / { if (-d $request_filename) { rewrite [^/]$ $scheme://$http_host$uri/ permanent; } } ## 执行命令重启 nginx synoservicecfg --restart nginx 

    参考

    15 replies    2020-06-16 14:25:10 +08:00
    stille
        1
    stille  
       May 12, 2020
    是的.当 DSM 的 http 跳 https,也会强制跳 5001 端口.

    甚至 webstation 里也没强制跳转 https 的选项,也不支持多主机头.

    群晖默认都是认为用户有 80/443 的
    alexlip
        2
    alexlip  
       May 12, 2020
    nginx 内置变量 $server_port 这个参数适用不?
    tankren
        3
    tankren  
       May 12, 2020
    谁说家宽没有 443 的? :doge
    nvkou
        4
    nvkou  
       May 12, 2020 via Android
    用 upstream 不行吗?直接反代。
    Atomo
        5
    Atomo  
       May 12, 2020
    cq65617875
        6
    cq65617875  
       May 12, 2020
    直接反代+1
    LokiSharp
        7
    LokiSharp  
       May 12, 2020
    rewrite [^/]$ $scheme://$http_host$uri/ permanent; 这边我记得得手动加 port 的
    moxuanyuan
        8
    moxuanyuan  
    OP
       May 12, 2020
    @tankren #3 大部分都没有吧。。
    moxuanyuan
        9
    moxuanyuan  
    OP
       May 12, 2020
    @nvkou #4 反代可以。。但要多用一台公网 server 。。。这不是我想要的方案
    tankren
        10
    tankren  
       May 12, 2020
    @moxuanyuan 试试 ipv6
    nvkou
        11
    nvkou  
       May 12, 2020 via Android
    @moxuanyuan 不是,你反代可以 4433>443 啊。干嘛还要额外公网
    qping
        12
    qping  
       May 12, 2020
    nginx 在 URL 末尾不加斜杠会 301 的问题,之前在生产环境碰到过,谢谢楼主给我解惑了。

    哈哈哈哈哈哈
    qping
        13
    qping  
       May 12, 2020
    控制面板 > 外部访问 有一个端口设置,楼主可以尝试下有没有用
    Kelan
        14
    Kelan  
       May 12, 2020
    @qping 大概 lz 要求内网还是直接用 443,那就解决不了问题。
    xsxu01
        15
    xsxu01  
       Jun 16, 2020
    还真有人碰到相同的问题了。 我最近也在为这个问题头疼。不知道是不是因为想用原因造成的。
    dsm 里面安装的 wordpreess 默认是在一个文件夹里面,不在根目录里面。我试过 web 的虚拟机也不灵。公网访问用花生壳就会导致错误跳转丢失端口信息。暂时还没有查到解决方案。对于我这个小白来说估计是比较复杂的问题。求大拿出现几下给搞定吧。
    About     Help     Advertise     Blog     API     FAQ     Solana     1421 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 48ms UTC 17:04 PVG 01:04 LAX 10:04 JFK 13:04
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86