Как правильно реализовать редирект с HTTP www.domain.com и domain.com на https
И с HTTPS www.domain.com на domain.com ?
Чтобы не делать такой костыль, подскажите верное решение
server {
listen 80;
server_name www.domain.com domain.com;
return 301 https://domain.com$request_uri;
access_log off;
error_log off;
}
server {
listen 443 ssl http2;
access_log off;
error_log off;
server_name www.domain.com;
return 301 https://domain.com$request_uri;
ssl on;
ssl_certificate /var/www/domain.com/ssl/origin.pem;
ssl_certificate_key /var/www/domain.com/ssl/private.key;
}
server {
listen 443 ssl http2;
ssl on;
ssl_certificate /var/www/domain.com/ssl/origin.pem;
ssl_certificate_key /var/www/domain.com/ssl/private.key;
add_header Strict-Transport-Security "max-age=15768000" always;
ssl_protocols TLSv1.2;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
root /var/www/domain.com/public;
index index.php;
server_name domain.com;