[英]How to redirect 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
. localhost:9292/json
为localhost/json
。
But What I want is 但是我想要的是
localhost:9292/json
to 'localhost' localhost:9292/json
为'localhost'
localhost:9292/json/post
to 'localhost/post' localhost:9292/json/post
到“本地主机/ post”
I think what I need to do is set root or do some rewrite, Anyone has some idea? 我认为我需要做的是设置root或进行一些重写,有人有想法吗?
If you want to pass all connections from port 9092 to 80 you are listening the wrong port. 如果要将所有连接从端口9092传递到80,则您正在侦听错误的端口。
Change the port you are listening to 9092: 更改您正在侦听的端口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;
}
}
Try to avoid use root inside the location block, it's a common pitfall as explained in nginx documentation 尝试避免在位置块内使用root,这是一个常见的陷阱,如nginx文档中所述
Also you will need to configure another server to listen port 80. 另外,您将需要配置另一台服务器以侦听端口80。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.