Answer the question
In order to leave comments, you need to log in
How to set up a redirect from www to without www?
Good day to all, I read a lot of manuals on Google, but none of them work, I hope for your help) I
installed an ssl certificate for nginx via ppa: python-certbot-nginx, after installation and automatic configuration, the config became like this.
Now there is a redirect from http to https, but how to make it redirect from www to https without www, no idea, no matter how I abuse the config, it doesn’t want to work :C
/etc/nginx/sites-available/site.ru
server {
listen 443 ssl;
root /var/www/SonyTwo;
ssl_certificate /etc/letsencrypt/live/site.ru/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/site.ru/privkey.pem; # managed by Certbot
ssl_dhparam /etc/nginx/dhparam.pem;
index index.html index.htm index.nginx-debian.html;
server_name site.ru;
location / {
try_files $uri $uri/ =404;
}
}
server {
if ($host = www.site.ru) {
return 301 https://$host$request_uri;
}
if ($host = site.ru) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name site.ru;
return 405; # managed by Certbot
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question