NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
newtonMiku
V2EX  ›  NGINX

关于反代的 location 中 uri 有 https 的问题

  •  
  •   newtonMiku ·
    newton-miku · Apr 25, 2024 · 2273 views
    This topic created in 755 days ago, the information mentioned may be changed or developed.

    RT,最近在香港的机器上做 GitHub 和 mikan 的反代,方便家里的设备在无代理情况下只需要增加一个前缀即可访问这些服务

        location ~ /^(?:https?:\/\/)?mikanani\.me(.*) {
            # 匹配到 URI 路径中含有"https://mikanani.me"的情况
            proxy_ssl_server_name on;
            proxy_pass 'https://mikanani.me/$1';
            sub_filter 'mikanani.me' $my_filter;
            sub_filter_once off;
    
            # Check if the request is for RSS
            add_header X-Request-URL https://mikanani.me$request_uri;
        }
    

    正常的如果是 location /的话直接改对应的域名即可,但是想一个域名实现对好几个站的反代,(假设我的域名是 abc.com) 我访问 abc.com/abc 和访问 abc.com/https://mikanani.me/abc,两者都应该反代到 https://mikanani.me/abc ,求问该如何实现

    7 replies    2024-04-26 17:31:45 +08:00
    mohumohu
        1
    mohumohu  
       Apr 25, 2024
    用 caddy 会简单很多。
    LinePro
        2
    LinePro  
       Apr 25, 2024
    说个题外话,mikan 有官方的反代
    https://mikanime.tv/
    newtonMiku
        3
    newtonMiku  
    OP
       Apr 25, 2024
    @LinePro 好吧,那 GitHub 呢,主要是想研究下 nginx 能不能实现这种路径带完整连接的
    ysc3839
        4
    ysc3839  
       Apr 26, 2024 via Android
    不建议用字符串替换的方案,实际情况很复杂,总会出现一些问题的。
    内网设备无代理访问的话,可以考虑用 sniproxy 。
    newtonMiku
        5
    newtonMiku  
    OP
       Apr 26, 2024
    @ysc3839 不是啊,类似于 ghproxy 这种的,在 GitHub 的链接前加个前缀即可实现对 GitHub 资源的代理就行啊
    ysc3839
        6
    ysc3839  
       Apr 26, 2024 via Android
    @newtonMiku 你发的配置文件里不是有用到 sub_filter 吗?这个就是字符串替换。
    newtonMiku
        7
    newtonMiku  
    OP
       Apr 26, 2024
    @ysc3839 #6 问题是我这个带原本 https 的匹配不上,不知道是写的正则有问题还是怎么,他只会匹配 location /的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3199 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 10:53 · PVG 18:53 · LAX 03:53 · JFK 06:53
    ♥ Do have faith in what you're doing.