简体   繁体   English

配置Varnish 4个多个域的不同端口

[英]Configure Varnish 4 multiple domains different ports

I got this to load both the websites, however I am unable to log into both wordpress websites. 我可以同时加载两个网站,但是无法登录两个wordpress网站。

backend websiteone {
    .host = "127.0.0.1";
    .port = "7070";
}
backend websitetwo {
    .host = "127.0.0.1";
    .port = "2082";
}
    sub vcl_recv {
    if (req.http.host ~ "^(.*\.)?websiteone\.com$") {
    set req.backend_hint = websiteone;
    return (hash);
}
    if (req.http.host ~ "^(.*\.)?websitetwo\.com$") {
    set req.backend_hint = websitetwo;
    return (hash);
    }
}

Here is what I did to resolve this issue: 这是我为解决此问题所做的工作:

 mkdir /etc/varnish/sites-enabled mkdir / etc / varnish / sites-enabled 

 cd /etc/varnish/sites-enabled cd / etc / varnish / sites-enabled 

 nano siteone.com.vcl 纳米siteone.com.vcl 

sub vcl_recv {
    if (req.http.host == "siteone.com") {
        if (req.url ~ "/(cart|my-account|checkout|addons|/?add-to-cart=)") {
        return (pass);
        }
    }
}

 nano sitetwo.com.vcl 纳米sitetwo.com.vcl 

backend sitetwo {
    .host = "127.0.0.1";
    .port = "2082";
}

sub vcl_recv {
       if (req.http.host == "sitetwo.com") {
           set req.backend_hint = sitetwo;
    }
}

Then I had to edit /etc/varnish/default.vcl 然后我必须编辑/etc/varnish/default.vcl

 cd /etc/varnish/ cd / etc /清漆/ 

 nano default.vcl nano default.vcl 

The backend is configured for sitetwo as you can see above, but the backend for siteone is configured in default.vcl so I changed 如上所示,后端是为sitetwo配置的,但是siteone的后端是在default.vcl中配置的,所以我更改了

backend default {
    .host = "127.0.0.1";
    .port = "7070";
}

And added these two lines to the bottom of default.vcl 并将这两行添加到default.vcl的底部

 include "sites-enabled/siteone.com.vcl";
 include "sites-enabled/sitetwo.com.vcl";

Everything seems to be working correctly now! 现在一切似乎都正常运行! And if I have to add any more sites all I have to do is create sitetree.com.vcl in /sites-enabled folder and paste 而且,如果我需要添加更多站点,我要做的就是在/ sites-enabled文件夹中创建sitetree.com.vcl并粘贴

backend sitethree {
    .host = "127.0.0.1";
    .port = "port number";
}

sub vcl_recv {
       if (req.http.host == "sitethree.com") {
           set req.backend_hint = sitethree;
    }
}

Note: Siteone is running an ecommerce site so if you are not running a store then you should just be able to use the following in siteone.com.vcl 注意: Siteone正在运行一个电子商务网站,因此,如果您未在运行商店,则应该能够在siteone.com.vcl中使用以下内容

sub vcl_recv {
       if (req.http.host == "siteone.com") {
           set req.backend_hint = siteone;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM