I have tried all the solutions found on this site and others but am still having a problem with redirecting a wildcard subdomain with http to https. I still end up with
https://%2A.example.com/site_admin
The above url displays in Chrome and "This page can not be displayed" in IE and "Your connection is not private" from chrome on my phone.
The non-wildcard nginx server blocks work fine.
I have tried rewrite and redirect 301 in the server block for the http wildcards, but it still rewrites the url to %A2 (the *). I think the default server is using the server_name of *.example.com but even when using $host it still rewrites as the *. Is there another directive that needs to be included?
server {
listen 80;
server_name example.com www.example.com;
# tell users to go to SSL version this time
if ($ssl_protocol = "") {
rewrite ^ https://$server_name$request_uri? permanent;
}
}
server {
listen 443 ssl;
server_name example.com www.example.com;
## ssl and locations not shown
}
server {
listen 80;
server_name manager.example.com ;
# tell users to go to SSL version this time
if ($ssl_protocol = "") {
rewrite ^ https://$server_name$request_uri? permanent;
}
}
server {
listen 443 ssl;
server_name manager.example.com ;
## ssl and locations not shown
}
server {
listen 80 default_server;
server_name *.example.com "" ;
# tell users to go to SSL version this time
if ($ssl_protocol = "") {
rewrite ^ https://$host$request_uri? permanent;
#rewrite ^ https://$server_name$request_uri? permanent;
}
}
server {
listen 443 default_server;
server_name *.example.com ;
ssl on;
## other ssl and locations not shown
}
$host
. It's somewhat bewildering why you wouldn't just useserver { listen 80 default_server; return 301 https://$host$request_uri; }
(or very similar) to replace all three of your http server blocks.