Many sites have server name ip in their a records.
Showing duplicate content using 302 redirect on many domain names
How to make all redirect to only website server is actually using.
Config:
Varnish port 80
HTTPD port 8080
443 NGINX PROXY
Many sites have server name ip in their a records.
Showing duplicate content using 302 redirect on many domain names
How to make all redirect to only website server is actually using.
Config:
Varnish port 80
HTTPD port 8080
443 NGINX PROXY
Add the following in default.vcl file
sub vcl_recv {
if ( (req.http.host ~ "^(?i)www.example.com" || req.http.host ~ "^(?i)www.example.com") && req.http.X-Forwarded-Proto !~ "(?i)https") {
return (synth(750, ""));
}
}
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = "https://www.example.com" + req.url;
return(deliver);
}
}
And add the following to nginx configuration
server {
listen 80;
# Listen to your server ip address
server_name your-server-ip;
# Redirect all traffic comming from your-server-ip to your domain
return 301 $scheme://www.example.com$request_uri;
}
and restart varnish and nginx
service varnish restart && service nginx restart