【问题标题】:How to redirect localhost:9292/json to localhost:80/ using Nginx reverse proxy?如何使用 Nginx 反向代理将 localhost:9292/json 重定向到 localhost:80/?
【发布时间】:2013-04-25 19:23:14
【问题描述】:
 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;

        }
    }

配置有点工作,但它只是通过

localhost:9292/jsonlocalhost/json

但我想要的是

localhost:9292/json 到“本地主机”

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

我认为我需要做的是设置 root 或进行一些重写,有人有什么想法吗?

【问题讨论】:

    标签: nginx reverse-proxy


    【解决方案1】:

    如果您想将所有连接从端口 9092 传递到 80,那么您正在侦听错误的端口。

    更改你正在监听的端口9092:

    server {   
        listen 9092;
        server_name localhost;
    
        root /Users/Lin/Codes/JS/Emberjs/yeoman-ember/dist;
    
        location / {
            index index.html;
    
        }  
    
        location ~* ^/json {
            proxy_pass http://localhost:80;
            proxy_set_header  X-Real-IP  $remote_addr;
        }
    }
    

    尽量避免在 location 块中使用 root,这是一个常见的陷阱,如 nginx documentation 中所述

    您还需要配置另一台服务器来监听端口 80。

    【讨论】:

      猜你喜欢
      • 2019-11-19
      • 1970-01-01
      • 2014-08-16
      • 2015-10-18
      • 2020-11-27
      • 2022-10-20
      • 1970-01-01
      • 2013-05-16
      • 2013-09-14
      相关资源
      最近更新 更多