nginx proxy_pass 到一个目录

标签 nginx reverse-proxy

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

根“/”由CMS管理,而“其他”是我自己的程序(独立于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 文档:

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使请求正常化。我引用:

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.



这应该可以帮助那些找到这个页面的人。

关于nginx proxy_pass 到一个目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26449466/

相关文章:

nginx - 同一个 K8S 集群上的两个入口 Controller

node.js - 当尝试作为反向代理连接到 Node 应用程序时,Nginx 连接被拒绝

node.js - NodeJS API 的 Nginx 配置

http - 具有 ssl 和简单 acl 的 HAProxy http 模式表现异常

apache - Nginx反向代理配置

ssl - 如何在 Go ReverseProxy 中使用 TLS?

php - nginx + nodejs + php

linux - 如果某些参数不为空,则将 HTTP POST 请求重定向到另一个子域

amazon-web-services - AWS ELB 终端问题背后的 Jupyter notebook

nginx - Jenkins Https 反向代理配置在 centos 中不起作用