example.com -> 301 -> https://example.com
https://www.example.com -> 301 -> https://example.com
https://www.example.com/something -> 301 -> https://example.com/something
www.example.com/something -> 301 -> https://example.com/something
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name localhost example.com www.example.com;
#return 301 https://example.com$request_uri; -- почему тут был бесконечный редирект
# .......
server {
listen 80 ;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl ;
listen [::]:443 ssl ;
server_name localhost www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name example.com
... тут будет основной конфиг для вашего сервера
}