nginx proxy_pass到目录 [英] nginx proxy_pass to a directory

查看:648
本文介绍了nginx proxy_pass到目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置nginx将单个文件夹反向代理到一台服务器,将其余的根反向代理到另一台服务器?

How can I setup nginx to reverse proxy a single folder to one server and the rest of root to a different server?

根"/"由CMS管理,而"other"是我自己的程序(独立于CMS).

The root "/" is managed by CMS while the "other" is my own programs (independent of the CMS).

这是我当前的配置

server {
    listen  80;
    server_name www.example.com;
    rewrite     ^   https://$server_name$request_uri? permanent;
}

server {
    listen   443;
    ... <ssl stuff> ...

    server_name www.example.com;

    location /other {
        proxy_pass http://192.168.2.2/other ;
    }

    location / {
        proxy_pass http://192.168.1.1;
    }
}

推荐答案

对nginx文档的引用:

reference to nginx docs:

http://wiki.nginx.org/HttpCoreModule#location

http://wiki.nginx.org/HttpProxyModule#proxy_pass

您应将other位置更改为此:

location /other/ {
    proxy_pass http://192.168.2.2/other/ ;
}

请注意结尾的/.实际上,它有所不同,因为它得到proxy_pass来规范化请求.我引用:

Note the trailing /. It actually make a difference since it gets proxy_pass to normalize the request. I quote:

当请求传递到服务器时,与位置匹配的规范化请求URI的一部分将替换为[proxy_pass]指令中指定的URI.

when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the [proxy_pass] directive.

这应该对那些找到此页面的人有所帮助.

This should help those that find this page.

这篇关于nginx proxy_pass到目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆