V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
LIBQ
V2EX  ›  NGINX

老哥们 求助一个 nginx 的技术问题 怎么在反代替换链接数据

  •  
  •   LIBQ · 2022-01-10 21:04:44 +08:00 · 1948 次点击
    这是一个创建于 829 天前的主题,其中的信息可能已经有所发展或是发生改变。

    具体需求如图 怎么将 URL 中的aaabcd更改为aaabbd

    tupian

    8 条回复    2022-01-11 11:29:30 +08:00
    daimaosix
        1
    daimaosix  
       2022-01-10 21:09:20 +08:00
    location /aaabcd {
    proxy_pass 源站 /aaabbd;
    }

    这样不行吗?
    LIBQ
        2
    LIBQ  
    OP
       2022-01-10 21:13:36 +08:00
    @daimaosix 这个是一大串里面节选的 并不是目录
    sparktour
        3
    sparktour  
       2022-01-10 22:05:46 +08:00
    nginx 的 sub_filter 可以做到替换源站的字符串,参考 https://www.nginx.com/resources/wiki/modules/substitutions/
    cattyhouse
        4
    cattyhouse  
       2022-01-11 05:42:05 +08:00 via iPhone
    location / {
    # 网站镜像
    # 此时 root /var/www/html; 的内容不会再显示
    # limit_req zone=mylimit; # 启用限制
    # 先定义好要 mirror 的网站以及自己的网站
    set $upstream_server http://mirror_domain.tld;
    set $upstream_domain mirror_domain.tld;
    set $mydomain example.com;
    # use variable to avoid resoling failure that leads to start nginx failure
    # refer: https://sandro-keil.de/blog/let-nginx-start-if-upstream-host-is-unavailable-or-down/

    sub_filter_once off;
    sub_filter_types *;

    sub_filter $upstream_domain $mydomain;
    proxy_set_header Referer $upstream_server;
    proxy_set_header Host $upstream_domain;
    proxy_pass $upstream_server;
    }
    swcat
        5
    swcat  
       2022-01-11 09:38:44 +08:00
    openresty 解千愁
    xiwangzishi
        6
    xiwangzishi  
       2022-01-11 10:01:32 +08:00
    OpenResty: 这题我会
    LIBQ
        7
    LIBQ  
    OP
       2022-01-11 10:47:42 +08:00
    @cattyhouse 谢谢老哥 问题解决了
    darknoll
        8
    darknoll  
       2022-01-11 11:29:30 +08:00
    同问下,caddy 里面怎么做
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5230 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:45 · PVG 13:45 · LAX 22:45 · JFK 01:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.