E
E
enchikiben2016-09-05 16:49:33
Nginx
enchikiben, 2016-09-05 16:49:33

Redirecting to https://www.domain.com in nginx?

Good afternoon!
Tell me how to redirect to https://www.domain.com?
Redirecting to https is done like this:

server {
  listen *:80;
  server_name www.domain.com domain.com;
  location / {
    rewrite ^(.*)$ https://www.domain.com$1 permanent;
  }
}

but if the user enters https://domain.com then there is no redirection, tell me how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2016-09-05
@EnChikiben

server {
    listen              80;
    server_name www.domain.com domain.com;
    return 301 https://www.domain.com$request_uri ;
}

server {
    listen              443 ssl;
    server_name domain.com;
    return 301 https://www.domain.com$request_uri ;
}

server {
    listen              443 ssl;
    server_name www.domain.com domain.com;
    # основная секция
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question