M
M
Michael2017-02-09 20:29:00
Nginx
Michael, 2017-02-09 20:29:00

Redirect to https without www?

Hello.

It is necessary that the domain works only in the form https://domain.ru .

domain.ru   --> https://domain.ru
www.domain.ru   --> https://domain.ru
http://domain.ru   --> https://domain.ru
http://www.domain.ru   --> https://domain.ru
https://www.domain.ru   --> https://domain.ru


What is the most correct way to redirect today?

Current configuration:

server {
    listen      ип:80;
    server_name domain.ru www.domain.ru;
    return 301  https://domain.ru$request_uri;
}

server {
    listen      ип:443 ssl;
    server_name domain.ru;

...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wexter, 2017-02-09
@Wexter

start another server on port 443 with server_name www.domain.ru and redirect it to https://domain.ru

Z
zooks, 2017-02-09
@zooks

The one in the current config is the correct one.

D
Denis Semenov, 2017-02-18
@denisemenov

I use this option on VestaCP.
I think it will not be difficult to substitute your own values.

#default.tpl
server {
    listen      %ip%:%web_port%;
    server_name %domain_idn% %alias_idn%;
    return 301  https://%domain_idn%$request_uri;
}

#default.stpl
server {
    listen      %ip%:%web_ssl_port% http2 ssl;
    server_name %alias_idn%;
    return 301  https://%domain_idn%$request_uri;
    
#Не знаю, должно ли быть это или нет в этом server:
    ssl         on;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
}
server {
    listen      %ip%:%web_ssl_port% http2 ssl;
    server_name %domain_idn%;
    root        %sdocroot%;
    index       index.php index.html index.htm;

    ssl         on;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;

    location / {

    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question