简体   繁体   English

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

[英]How to rewrite localhost:9292/json to localhost:80/ using 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;

        }
    }

The configure kinda works, but it only pass 配置还可以,但是只能通过

localhost:9292/json to localhost/json.

But What I want is 但是我想要的是

localhost:9292/json to 'localhost'

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

I think what I need to do is set root or do some rewrite, Anyone has some idea? 我认为我需要做的是设置root或进行一些重写,有人有想法吗?

add a rewrite rule before the proxy_pass proxy_pass之前添加重写规则

location /json {
    rewrite ^/json(.*) $1;
    proxy_pass http://localhost:9292;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Nginx反向代理将localhost:9292 / json重定向到localhost:80 /? - How to redirect localhost:9292/json to localhost:80/ using Nginx reverse proxy? 如何使用nginx作为反向代理将localhost:9292定向到子域foo.localhost /? - How to use nginx as reverse proxy to direct localhost:9292 to a sub domain foo.localhost/? 简单地从本地主机:80到本地主机:8080的nginx反向代理不起作用 - Simply nginx reverse proxy from localhost:80 to localhost:8080 not working nginx反向代理到本地主机 - nginx reverse proxy to localhost 如何在本地主机上设置Nginx反向代理 - How to set nginx reverse proxy at localhost nginx反向代理以避免本地主机的cors错误 - nginx reverse proxy to avoid cors error with localhost nginx反向代理到在localhost上运行的后端 - nginx reverse proxy to backend running on localhost Nginx反向代理不适用于本地主机上的Nodejs - Nginx Reverse Proxy not working with Nodejs at localhost Nginx:如何将代理从外部请求反向到特定的 localhost url - Nginx: How to reverse proxy from external request to specific localhost url 如何在 Docker for Windows 上使用 nginx 作为本地主机的反向代理? - How to use nginx on Docker for Windows as reverse proxy for localhost?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM