M
M
motomac2016-11-27 16:53:51
Nginx
motomac, 2016-11-27 16:53:51

How to configure nginx redirect to https only for the main domain?

Faced a strange problem. In a very typical scenario of a redirect from http to https (and from www to non-www), for some reason this config also affects other subdomains. For example, the sub.site.ru subdomain also starts redirecting to https, which does not have it.

server {
  server_name site.ru www.site.ru;
  listen *:80;
  listen [::]:80;

  return 301 https://site.ru$request_uri;
}

server {
  # SSL configuration
  listen 443 ssl;
  listen [::]:443 ssl;
  server_name site.ru;
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
motomac, 2016-11-27
@motomac

It was all about includeSubdomains . Should have removed this from:

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question