nginx 反向代理的问题。

2016-07-07 11:41:17 +08:00
 csdreamdong
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 路由匹配不上。

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

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

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

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

uwsgi 的配置里,可以配。
csdreamdong
2016-07-07 18:03:32 +08:00
@qingchn 嗯。已找到方案,就是不想改 django 的形态。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/290822

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX