Answer the question
In order to leave comments, you need to log in
How to redirect from site.ru to www.site.ru and from https://site.ru to https://www.site.ru in nginx?
Comrades, tell me, please, on a subject. There is an nginx config:
server {
listen 80;
server_name site.ru;
location / {
return 301 http://www.site.ru$request_uri;
}
}
server {
listen 80;
listen 443 ssl;
server_name www.site.ru;
ssl_certificate cert.crt;
ssl_certificate_key key.key;
Answer the question
In order to leave comments, you need to log in
Solution to my question:
server {
listen 80;
listen 443 ssl;
server_name example.com;
ssl_certificate path/to/cert;
ssl_certificate_key path/to/key;
return 301 $scheme://www.example.com$request_uri;
}
server {
listen 80;
listen 443 ssl;
server_name www.example.com;
ssl_certificate path/to/cert;
ssl_certificate_key path/to/key;
# rest goes here...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question