Answer the question
In order to leave comments, you need to log in
How to make a site accessible only via https and without www?
There is
a site https://example.com I want everything to be only through https and without www, in other cases there should be a 301 redict to the corresponding https without www ulr, that is:
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; -- why there was an endless redirect
# .......
Answer the question
In order to leave comments, you need to log in
because you are redirecting to yourself.
You need to do something like this:
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
... тут будет основной конфиг для вашего сервера
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question