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

nginx 反向代理的问题。

  •  
  •   csdreamdong · 2016-07-07 11:41:17 +08:00 · 3578 次点击
    这是一个创建于 2850 天前的主题,其中的信息可能已经有所发展或是发生改变。
    server {
        listen       80;
        server_name  www.hehehe.com;
    
        charset utf-8;
        
        location /test {
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:3031;
        }
    }
    
    

    对于 http://hehehe.com/test/index 类似这样的请求 反向代理到了 uwsgi, 是个 django 应用

    然后我只想要把 /index 这部分的 url 反向代理过去,,而不是 /test/index

    现在 /test/index 导致我的 django 的 url 路由匹配不上。

    12 条回复    2016-07-07 18:03:32 +08:00
    alex321
        1
    alex321  
       2016-07-07 11:49:36 +08:00
    / 做 uwsgi
    /text/index 不做
    zjqzxc
        2
    zjqzxc  
       2016-07-07 11:49:40 +08:00
    遇到过类似的问题,处理方法是修改路由把 /test 部分吃掉
    shyling
        3
    shyling  
       2016-07-07 13:00:40 +08:00 via iPad
    用正则 location
    ruanjf
        4
    ruanjf  
       2016-07-07 13:03:10 +08:00
    uwsgi_pass 127.0.0.1:3031/;
    加斜杠试试
    dixyes
        5
    dixyes  
       2016-07-07 13:06:15 +08:00 via Android
    rewrite 阶段在 uwsgi_pass 之前么 如果是的话 可以用 set 命令修改 location 变量试试(我只是脑洞 没试过
    hbprotoss
        6
    hbprotoss  
       2016-07-07 13:47:07 +08:00
    location /test 里面加

    rewrite /test(.*) $1 break;
    csdreamdong
        7
    csdreamdong  
    OP
       2016-07-07 13:57:16 +08:00
    @hbprotoss rewrite 之后

    www.hehehe.com/test/index
    访问后,就会被指向 www.hehehe.com/index
    0 0 ,这样子就是 404 页面。
    hbprotoss
        8
    hbprotoss  
       2016-07-07 14:09:06 +08:00
    @csdreamdong 不是吧,难道 rewrite 对 uwsgi_pass 不起作用。。
    hbprotoss
        9
    hbprotoss  
       2016-07-07 14:16:55 +08:00   ❤️ 1
    qingchn
        10
    qingchn  
       2016-07-07 14:24:50 +08:00
    django 里面把这条路由加上 /test/index
    csdreamdong
        11
    csdreamdong  
    OP
       2016-07-07 18:03:02 +08:00
    @hbprotoss 嗯。正解。

    mount = /test=/data/workspace/mblog/mblog/wsgi.py
    manage-script-name = true

    uwsgi 的配置里,可以配。
    csdreamdong
        12
    csdreamdong  
    OP
       2016-07-07 18:03:32 +08:00
    @qingchn 嗯。已找到方案,就是不想改 django 的形态。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2457 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:07 · PVG 09:07 · LAX 18:07 · JFK 21:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.