exuxu
V2EX  ›  问与答

nginx url 代理服务的问题

  •  
  •   exuxu · Jan 5, 2018 · 1408 views
    This topic created in 3053 days ago, the information mentioned may be changed or developed.

    我想实现访问
    ip 解析到 www.test.com

    www.test.com/sub1
    www.test.com/sub2
    

    nginx 用的是以下(简化)配置

    server {
            listen       80;
            server_name  www.test.com;
            location  /sub1/ {
                     proxy_pass http://127.0.0.1:3000/;
            }
            location /sub2/ {
                    proxy_pass http://127.0.0.1:4000/;
            }
    }
    

    端口 3000 的服务全程是 http://www.test.com/sub1/xxxxxxx 为什么不可行....

    4 replies    2018-01-05 15:32:20 +08:00
    exuxu
        1
    exuxu  
    OP
       Jan 5, 2018
    ~ 沉了 ~
    h4lbhg1G
        2
    h4lbhg1G  
       Jan 5, 2018
    其实这种你可以开一个`nc -l 3000`调试下,看看打过去的是啥。因为两个都有结尾的 /,那么实际上应该相当于访问的`http://127.0.0.1:3000/xxxxxx` 。

    优雅的小尾巴:欢迎使用和 star 我的命令行工具 https://github.com/rexdf/CommandTrayHost
    exuxu
        3
    exuxu  
    OP
       Jan 5, 2018
    @h4lbhg1G 试过了其它代理服务能用,但是部署的测试服务,没法使用,测试服务会对未登录 redirect,可能是它导致的,现在是部分 header 页面加载出来了。
    h4lbhg1G
        4
    h4lbhg1G  
       Jan 5, 2018
    @exuxu 那就是是代理服务器对头或者源有检测了,如果有控制权看一下对方接的 http 头就好了。话说这样的话,你的问题的里面简化版等于啥也没说。

    如果没有控制权,那要做一系列的替换。对于重定向用 proxy_redirect,对于 css/html/js 用三方插件 subs_filter
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   941 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 19:38 · PVG 03:38 · LAX 12:38 · JFK 15:38
    ♥ Do have faith in what you're doing.