문제

I have 1 server with 2 IP addresses: eth0 = 1.2.3.4 eth0:0 = 5.6.7.8

/etc/hosts

127.0.0.1 localhost
1.2.3.4 domain1.com
5.6.7.8 domain2.net

In this server I have Apache running with the following configuration (/etc/httpd/conf/httpd.conf):

...
Listen 1.2.3.4:8080
Listen 5.6.7.8:8080
...
<VirtualHost 1.2.3.4:8080>
DocumentRoot /var/www/domain1.com/public_html
...
</VirtualHost>
<VirtualHost 5.6.7.8:8080>
DocumentRoot /var/www/domain2.net/public_html
...
</VirtualHost>

So far so good, and I can have my webserver working OK.

Then I have installed Varnish Cache, with the following parameters:

/etc/sysconfig/varnish

NFILES=131072
MEMLOCK=82000
NPROCS="unlimited"
RELOAD_VCL=1
VARNISH_LISTEN_PORT=80
DAEMON_OPTS="-a domain1.com:80 \
             -T domain1.com:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"
DAEMON_OPTS="-a domain2.net:80 \
             -T domain2.net:6083 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,512m"

/etc/varnish/default.vcl

backend domain1 {
  .host = "1.2.3.4";
  .port = "8080";
}
backend domain2 {
  .host = "5.6.7.8";
  .port = "8080";
}
sub vcl_recv {
    if (req.http.host == "domain1.com") {
        set req.http.host = "domain1.com";
        set req.backend = domain1;
        return (lookup);
    }
    if (req.http.host == "domain2.net") {
        set req.http.host = "domain2.net";
        set req.backend = domain2;
        return (lookup);
    }
}

But I can reach the website domain2.net but not the domain1.com.

When querying the ports listening on my server, I can notice the following:

user@host# netstat -an | more
tcp        0      0 5.6.7.8:80              0.0.0.0:*                   LISTEN
tcp        0      0 5.6.7.8:8080            0.0.0.0:*                   LISTEN
tcp        0      0 1.2.3.4:8080            0.0.0.0:*                   LISTEN
tcp        0      0 5.6.7.8:6083            0.0.0.0:*                   LISTEN

Does anyone know why is Varnish ignoring all 1.2.3.4 / domain1.com configuration? And how to make it work?

Thanks in advance.

도움이 되었습니까?

해결책

In your /etc/sysconfig/varnish, you just write the variable DAEMON_OPTS two times and so only the second set of parameters is passed to the varnish daemon. But since you use only one vcl script anyway, why do you want to start two varnish daemons?

One daemon on both IPs will work, so you can simply remove the domain part in your DAEMON_OPTS and varnish will listen on all interfaces:

DAEMON_OPTS="-a :80 \
         -T localhost:6082 \
         -f /etc/varnish/default.vcl \
         -S /etc/varnish/secret \
         -s malloc,256m"

-T is for the management interface. Mostly you only want this accessable from localhost

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top