Question
How to set up mutiple domains with Nginx and Varnish in same server
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?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×