Answer the question
In order to leave comments, you need to log in
What could be the reason that the redirect in nginx does not work?
I open the file /etc/nginx/sites-enabled/for editing, I
prescribe the domain before the current server, I tried after the current one
server {
listen 80;
listen [::]:80;
server_name www.домен;
return 301 $scheme://домен$request_uri;
}
server {
listen 80;
listen [::]:80;
server_name www.домен домен;
if ($host ~ "^www\.(.*)$") {
return 301 https://домен$request_uri;
}
if ($host = 'www.домен' ) {
rewrite ^(.*)$ https://домен$1 permanent;
}
Answer the question
In order to leave comments, you need to log in
All figured out.
With all these redirects and certificates. Total.
1. we check the certificate itself, whether the domain and www.domain are included in it, if something is missing, add it, since checking the certificate is more important than the nginx settings, redirects work, but you don’t see it until you allow you to go to the next page without a certificate ( recent browser updates may not allow this, IE gives me a choice, but chrome doesn’t)
if cerbot is used, then the command where we list all the necessary domains
certbot -d domen -d www.domen --expand
2. leave in the main config
server {
...
server_name домен;
...
}
server {
listen 80; #для http редирект сразу на https и без www
server_name www.домен;
return 301 https://домен$request_uri;
}
server {
listen 443; #для https
server_name www.домен;
return 301 $scheme://домен$request_uri;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question