V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
jsjcjsjc
V2EX  ›  问与答

nginx 如何只反向代理到网站的二级目录

  •  
  •   jsjcjsjc · 2018-10-22 20:23:10 +08:00 · 2062 次点击
    这是一个创建于 2229 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我 nas 上 bt 的路径是 olddomain.myqnapcloud.com:60080/rutorrent/ 原来的配置是这样的,这样我访问的时候是 newdomain.com/rutorrent/。但我想把结尾的 rutorrent 去掉

    就是访问 newdomain.com ,反向代理到 olddomain.myqnapcloud.com:60080/rutorrent/ 求指点,感谢感谢

    server
            {
                    listen 80;
                    server_name newdomain.com;
    
                    if ($http_user_agent ~* (baiduspider|360spider|haosouspider|googlebot|soso|bing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twiceler)) {
                    return  403;
                    }
    
                    location / {
                    sub_filter olddomain.myqnapcloud.com:60080 newdomain.com;
                    sub_filter_once off;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Referer http://olddomain.myqnapcloud.com:60080;
                    proxy_set_header Host olddomain.myqnapcloud.com:60080;
                    proxy_pass http://olddomain.myqnapcloud.com:60080;
                    proxy_set_header Accept-Encoding "";
                    }
    }
    
    5 条回复    2018-10-23 22:28:47 +08:00
    Tink
        1
    Tink  
       2018-10-23 08:43:03 +08:00 via iPhone   ❤️ 1
    二级目录 location 里单独写 auth
    Tink
        2
    Tink  
       2018-10-23 08:43:26 +08:00 via iPhone   ❤️ 1
    脑子乱了,忽略我
    jsjcjsjc
        3
    jsjcjsjc  
    OP
       2018-10-23 08:49:52 +08:00
    @Tink 哥,别啊~~快清醒清醒
    xiaoxinshiwo
        4
    xiaoxinshiwo  
       2018-10-23 15:29:52 +08:00   ❤️ 1
    jsjcjsjc
        5
    jsjcjsjc  
    OP
       2018-10-23 22:28:47 +08:00
    @xiaoxinshiwo 确实。。。感谢
    ```
    server
    {
    listen 80;
    server_name new.abc.io;

    if ($http_user_agent ~* (baiduspider|360spider|haosouspider|googlebot|soso|bing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twiceler)) {
    return 403;
    }

    location / {
    sub_filter olddomain.myqnapcloud.com:60080/rutorrent/ new.abc.io;
    sub_filter_once off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Referer http://olddomain.myqnapcloud.com:60080/rutorrent/;
    proxy_set_header Host olddomain.myqnapcloud.com:60080;#此处注意
    proxy_pass http://olddomain.myqnapcloud.com:60080/rutorrent/;
    proxy_set_header Accept-Encoding "";
    }
    }
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1665 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:56 · PVG 00:56 · LAX 08:56 · JFK 11:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.