L
L
ligisayan2020-07-21 17:34:34
Nginx
ligisayan, 2020-07-21 17:34:34

How to set up a redirect c www on nginx?

Hello! There is a need to set up a 301 redirect from www on nginx According to the recommendations, it should be something like this:

server {
    server_name www.devisers.in;
    return 301 $scheme://devisers.in$request_uri;
}


But, I have server_name set to a variable (local and real host are different)
server {
    listen 80;
    server_name ${VIRTUAL_HOST};
}


How in that case to register the rule c www ?

**UDP**
Registered as a separate entry
server {
    listen  80;
    server_name  www.${VIRTUAL_HOST};
    return 301 $scheme://$server_name$request_uri;
}

But, when you go to www , browsers swear at
Connection not established: Probable security risk

(Ssl network installed on the site)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2020-07-21
@ky0

Everything you described is trivially done with rewrite directives: https://nginx.org/ru/docs/http/ngx_http_rewrite_mo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question