ssl - Nginx redirects http to https for subdomain, but shows top level domain -


i'm trying configure nginx work following: top-level domain, example.com, being accessed http, redirects https. subdomains must redirect https (obviously, subdomain must redirect itself, https).

here configuration (file default):

server {         listen 80;         listen [::]:80;          server_name example.com *.example.com;          return 301 https://$host$request_uri; }  server {         listen 443 ssl default_server;         listen [::]:443 ssl default_server;         include snippets/ssl-example.com.conf;         include snippets/ssl-params.conf;          server_name example.com www.example.com;          root /home/user/wwwroot;          index index.html index.htm index.nginx-debian.html;          location / {                 # first attempt serve request file,                 # directory, fall displaying 404.                 try_files $uri $uri/ =404;         } } 

here configuration 'yt' subdomain (file yt)

server {    listen 443 ssl;    server_name yt.example.com;     location ^~ /.well-known {       allow all;       root /home/user/wwwroot;    }     location / {        proxy_set_header        x-real-ip       $remote_addr;        proxy_set_header        x-forwarded-for $proxy_add_x_forwarded_for;        proxy_set_header x-forwarded-host $http_host;        proxy_set_header x-forwarded-proto $scheme;          proxy_pass http://localhost:8080;    }  } 

as 1 can see, yt.example.com passes request application (youtrack in case).

redirect example.com , www.example.com works fine, yt.example.com behaves strangely. when access http://yt.example.com, nginx redirects https://yt.example.com, serves content root /home/user/wwwroot specified @ default file. when hit refresh button, browser reloads page @ https://yt.example.com , nginx passes request application i've expected. when redirects http https not pass request, when request using https redirects.

i'm not nginx-guru, need help.


Comments