0
votes

Now I have this setup

Port 80 redirects to port 443 with nginx, then it use varnish as upstream, now when it comes back, I need to setup some variables in nginx, fx

My domains are with subdomains such as en.mydomain.com, de.mydomain.com

server {
  server_name 127.0.0.1;
  listen 8080;
  $VAR = en;
}

server {
  server_name 127.0.0.1;
  listen 8080;
  $VAR = de;
}

How do I figure out which domain was used to get to this - I think I need to have multiple ports and then varnish should redirect to each backend depending on the domain, how do I set varnish to return to a backend depending on the domain?

1

1 Answers

0
votes

If the IP address and the port of your Varnish backend is the same for each subdomain, you shouldn't worry about this: the Host header of each request will result in different cache keys in Varnish, but Nginx will also serve the right website based on this Host header.

In the config you shared, you should make sure en.mydomain.com and de.mydomain.com are part of the Nginx server_name. This will allow Nginx to match the right hostname.

If you go to en.mydomain.com, Varnish will extract the host and the URL, and will turn this into a unique cache key. If it needs to fetch data from Nginx, Nginx will handle it for you.