proxy_pass

时间:2015-09-18 10:04:58

标签: nginx

我希望我的nginx能够将不同的uri传递给不同的后端,所以我认为我这样做了:

    server {
    listen 8090;

    access_log /var/log/nginx/nginx_access.log combined;
    error_log /var/log/nginx/nginx_error.log debug;

    location /bar {
        proxy_pass http://backend2;
    }

    location /foo {
        proxy_pass http://backend2;
    }

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


upstream backend1 {
    server 10.33.12.41:8080;
    server 127.0.0.1:8080 max_fails=3;
}

upstream backend2 {
    server 10.33.12.41:8080;
    server 10.33.12.43:8080;  
}

如果我打电话给wget http://mynginxserver:8090/,我会得到以下内容:

wget http://mynginxserver:8090/
--2015-09-18 11:58:21--  http://mynginxserver:8090/
Connecting to mynginxserver:8090... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://backend1/
[following]
--2015-09-18 11:58:21--  http://backend1/
Resolving backend1 (backend1)... failed: Temporary failure in name resolution.
wget: unable to resolve host address ‘backend1’

为什么要尝试解析backend1?我不明白。请帮忙 ;) 问候, Snooops

1 个答案:

答案 0 :(得分:1)

我的错: 1它应该在这里postet:serverfault.com 它已经解决了第二个问题: https://serverfault.com/questions/590044/nginx-proxy-pass-config