【问题标题】:Pass the domain from nginx as frontend to varnish as backend将域从 nginx 作为前端传递到清漆作为后端
【发布时间】:2014-06-28 21:42:58
【问题描述】:

更新:已解决!检查我对这个问题的回答。

我有一个 nginx 服务器作为前端,它使用 varnish 作为他的后端,而 varnish 使用 apache2 作为他的后端。类似:

nginx:

Nginx 被配置为监听 *:80

location / {
    proxy_pass   http://127.0.0.1:81;
}

清漆:

Varnish 配置为监听 127:0.0.1:81

backend 1 {
        .host = "127.0.0.1";
        .port = "8081";

        ...
}

backend 2 {
        .host = "127.0.0.1";
        .port = "8080";

        ...
}

sub vcl_recv {

    if (req.http.host == <1 domain>) {
        # setting the backend to 1
        set req.backend = 1;
    } else {
        # setting the backend to 2
        set req.backend = 2;
    }

    ...

}

apache2:

apache 配置为监听 127.0.0.1:8080 和 127.0.0.1:8081

// ports.conf

VirtualHost 127.0.0.1:8080
Listen 8080

VirtualHost 127.0.0.1:8081
Listen 8081

// other vhost confs

<VirtualHost 127.0.0.1:8080>
...
</VirtualHost>

<VirtualHost 127.0.0.1:8081>
...
</VirtualHost>

如何将 HTTP 主机(如 example.com 或 secure.example.com)从 nginx 传递到 varnish,以识别请求的站点?

【问题讨论】:

    标签: apache nginx varnish


    【解决方案1】:

    这是我的解决方案,对我有用。也欢迎其他答案!

    只需在 nginx 中将 proxy_set_header Host www.example.com; 添加到 location / { 即可。

    类似这样的:

    server {
    
        server_name example.com www.example.com;
    
        location / {
                proxy_pass   http://127.0.0.1:8080;
    
                # THIS line was added:
                proxy_set_header Host www.example.com;
        }
    
        ...
    
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-21
      • 2012-11-12
      • 1970-01-01
      • 2014-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      相关资源
      最近更新 更多