如何将localhost:9292 / json重写为localhost:80 /使用Nginx反向代理?

时间:2013-08-06 02:01:22

标签: nginx reverse-proxy

server {   
        listen 80;
        server_name localhost;
        location / {
            index index.html;
            root /Users/Lin/Codes/JS/Emberjs/yeoman-ember/dist;
        }  

        location ~* ^/json {
            root
            proxy_pass http://localhost:9292;

        }
    }

configure kinda有效,但只传递

localhost:9292/json to localhost/json.

但我想要的是

localhost:9292/json to 'localhost'

`localhost:9292 / json / post to' localhost / post'

我认为我需要做的是设置root或做一些重写,任何人都有一些想法?

1 个答案:

答案 0 :(得分:1)

proxy_pass

之前添加重写规则
location /json {
    rewrite ^/json(.*) $1;
    proxy_pass http://localhost:9292;
}