I've read in Nginx docummentation that instead of using IFs, new server blocks should be made.
I have tried making another block listening to 443 ssl, just to set there redvi.eu (non www) and then redirect it accordingly. It fails because of duplication.
How is the correct way to redirect https non-www here?
server { listen 80 default_server; server_name www.redvi.eu redvi.eu; return 301 https://www.redvi.eu$request_uri; } server { server_name www.redvi.eu; root /home/deploy/redvi/current/public; passenger_enabled on; passenger_app_env production; location /cable { passenger_app_group_name redvi_websocket; passenger_force_max_concurrent_requests_per_process 0; } # Allow uploads up to 100MB in size client_max_body_size 100m; location ~ ^/(assets|packs) { expires max; gzip_static on; } listen [::]:443 ssl ipv6only=on; # managed by Certbot listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/www.redvi.eu/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/www.redvi.eu/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot }