0

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
Jack Duldi
  • 19
  • 9

1 Answers1

0

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
Vinoth Rc
  • 172
  • 5
  • is this command good ? i wanna mention that varnish is looking on port 80 so i can't config nginx on port 80 nginx is not even used only for redirecting 443 using proxy to varnish 80 – Jack Duldi Mar 17 '20 at 18:35