nginx代理\u传递配置

nginx代理\u传递配置,nginx,virtualhost,proxypass,Nginx,Virtualhost,Proxypass,我需要代理几个URL到不同的主机。实际上,我正在使用具有不同端口的相同主机来测试我的nginx配置。这是我的虚拟主机定义: server { listen 8081; server_name domain.com; location /Plasmid/ { proxy_pass http://localhost:8000/Plasmid/; } location /_community/ { pro

我需要代理几个URL到不同的主机。实际上,我正在使用具有不同端口的相同主机来测试我的nginx配置。这是我的虚拟主机定义:

server {
    listen       8081;
    server_name  domain.com;

    location /Plasmid/ {
        proxy_pass   http://localhost:8000/Plasmid/;
    }


    location /_community/ {
         proxy_pass   http://localhost:8082/comments_api/ ;
    }

    location / {
        # rewrite cq_user_authenticated===(.*)/(.*)/iuuid=(.*)/commenti.html$  /Plasmid/comments/legacy/$3/$1 ;
        # rewrite querystring===(.*)$  /Plasmid/comments/legacy/$1 ;
        # rewrite cq_user_authenticated===([^&]*)&/.*uuid=([^/]*) /comments_api/legacy/$2 ;
        # rewrite userdetails(.*)  /Plasmid/comments/user_details ;
        root   html;
        index  index.html index.htm;
    }

}
当然,我的主机文件有domain.com的映射

当我调用url时:我得到一个HTTP404

如果从配置中删除第二个位置:

location /_community/ {
    proxy_pass   http://localhost:8082/comments_api/ ;
}
我获得了所需的资源,但由于这些资源托管在不同的平台上,因此缺少某些部分:

[error] 1033#0: *1 open() "/usr/local/Cellar/nginx/1.2.6/html/_community/content
如何解决此问题?

做一点更改:

location ^~ /Plasmid/ {
   proxy_pass    http://localhost:8000/Plasmid/;
}

location ^~ /_comunity/ {
   proxy_pass    http://localhost:8082/comments_api/;
为什么呢?因为
^ ~
表示在您请求页面时从开始:

这符合那条规则。在您的配置中,您使用的是无标记和类似的东西:

location /anylocation
看起来你的nginx偏好规则

location / {

因为它使用root指令并在
html
文件夹中搜索_社区/内容(正如您在错误消息中看到的)

换句话说,
^ ~
的优先级高于
无标记
。还有一件事也有帮助,那就是在每个
proxy\u pass
指令之后添加
break
指令

location /Plasmid
location /_comunity