By 4checkervn
This is my problem
I have 2 domain : mysite1.com and mysite2.com and one digital ocean Droplet, I installed nginx and varnish, everything work well with mysite1.com and now I want to add more domain to my droplet - mysite2.com
This is my config in default.vcl
backend default {
.host = "127.0.0.1";
.port = "8080";
}
backend mysite2 {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.http.host == "mysite1.com" || req.http.host == "www.mysite1.com") {
set req.backend = default;
} elsif (req.http.host == "mysite2.com" || req.http.host == "www.mysite2.com") {
set req.backend = mysite2;
}
}
and now is ngix config in /etc/ngix/site-avaiable/mysite2
server {
server_name mysite2.com;
#server_name localhost;
listen 127.0.0.1:8080;
root /home/mysite2/sites/mysite2
// some bla bla here
}
My problem is whenever I try to connect to mysite2.com, everything with be move to mysite1.com.
If I turn off varnish, everthing is ok, but when I turn it on, I got this error, I think my config is not correct, but I don’t know why, any one have experience with it?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
It depends on which version of Varnish you’ve installed & configured.
Try changing:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
backend mysite2 {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.http.host == "mysite1.com" || req.http.host == "www.mysite1.com") {
set req.backend = default;
} elsif (req.http.host == "mysite2.com" || req.http.host == "www.mysite2.com") {
set req.backend = mysite2;
}
}
To:
Varnish 3.x
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.http.host ~ "^(www\.)?mysite1\.com$") {
set req.backend = default;
}
if (req.http.host ~ "^(www\.)?mysite2\.com$") {
set req.backend = default;
}
}
Varnish 4.x
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.http.host ~ "^(www\.)?mysite1\.com$") {
set req.backend_hint = default;
}
if (req.http.host ~ "^(www\.)?mysite2\.com$") {
set req.backend_hint = default;
}
}
… and then restart Varnish.
The above using a regex to match the request instead of using ||. Keeps it short and sweet and only requires that you change mysite# inside the regex.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.