Apache2 + varnish 4 + nginx

hello, I use varnish at port 80, apache2 8080 and nginx as proxy for ssl at 443.

the code I use in varnish/default.vcl

redirects http://domain.com -> https://www.domain.com

http://www.domain.com -> https://www.domain.com

but not https://domain.com -> https://www.domain.com

I searched over internet and tried to redirect in .htaccess, nginx, but no success. Is there any way to do this?

The code I used

sub vcl_recv {
 if ( (req.http.host ~ "^(?i)www.domain.com" || req.http.host ~ "^(?i)domain.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.domain.com" + req.url;
        return(deliver);
    }
}

0 Replies

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct