Apache 将域作为前端从nginx传递到作为后端的varnish
更新:解决!检查我对这个问题的回答 我有一个nginx服务器作为前端,它使用varnish作为后端,varnish使用apache2作为后端。比如: nginx: Nginx被配置为监听*:80Apache 将域作为前端从nginx传递到作为后端的varnish,apache,nginx,varnish,Apache,Nginx,Varnish,更新:解决!检查我对这个问题的回答 我有一个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";
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;
}
...
}
后端1{
.host=“127.0.0.1”;
.port=“8081”;
...
}
后端2{
.host=“127.0.0.1”;
.port=“8080”;
...
}
子vcl_recv{
如果(req.http.host==){
#将后端设置为1
设置req.backend=1;
}否则{
#将后端设置为2
设置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>
//ports.conf
VirtualHost 127.0.0.1:8080
听8080
VirtualHost 127.0.0.1:8081
听8081
//其他vhost会议
...
...
如何将HTTP主机(如example.com或secure.example.com)从nginx传递到varnish,以识别请求的站点?这是我的解决方案,对我来说很有用。其他答案也将受到欢迎 只需添加
proxy\u set\u头主机www.example.com代码>到nginx中的位置/{
大概是这样的:
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;
}
...
}