Answer the question
In order to leave comments, you need to log in
How to set up a redirect from http to https and from www to no-www?
In general, the essence of the question is in the title. I tried googling and came up with this
#redirect
server {
listen 80;
server_name "~^(www\.)?(.*)$" ;
return 301 https://$2$request_uri ;
}
#В этом блоке пытался оставлять строки с ssl и закомментированными и раскоментированными
server {
listen 443 ssl;
server_name "~^www\.(.*)$" ;
return 301 https://$1$request_uri;
#ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
#ssl_certificate_key /etc/letsencrypt/live/example.com/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
}
server {
#listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/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
#root directory
root /var/www/example.com/public;
#domain name
server_name example.com;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
}
http://example.com -> https://example.com
http://www.example.com -> https://example.com
https://www.example.com
the browser swears at the certificate. CHADNT? Thank you.
Answer the question
In order to leave comments, you need to log in
Your certificate must contain two domains with and without www. Or create a separate server with a certificate from www
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question