I already have a working configuration to redirect all non-existent subdomains to a specific domain. Now I want to add a configuration that redirects all HTTP requests to HTTPS on the same domain.
This config file does the subdomain redirects:
# redirect any non-existent subdomain (blah.domain.de -> domain.de)
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://domain.de$request_uri;
}
And this is the config I try to use for HTTP->HTTPS:
# redirect any HTTP request to its HTTPS address (http://domain.de/blub -> https://domain.de/blub)
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name domain.de mail.domain.de admin.domain.de;
return 301 https://$server_name$request_uri;
}
But this doesn't work because the default_server is defined twice. How can combine these two functions?
Do I really have to add the second config to every single subdomain config?