I currently have two nginx server blocks to process the requests to any subdomain under example.com
. Add subdomains under example.com
must be server only with HTTPS. And so the server blocks are as such:
server {
server_name ~^(.*)\.example\.com$;
root /var/www/x;
listen 443 ssl;
...
}
server {
listen 80;
server_name ~^(.*)\.example\.com$;
return 301 https://$host$request_uri;
}
Objective
Now, I also want to add a default server block for ANY other server names, but all of its traffic should only be served on HTTP, not HTTPS.
So the first trial was:
server {
listen 80 default_server;
server_name _;
root /var/www/app;
...
}
Which works great, but if the processed request was as such: https://abc.def.com
then the user will get the "Your connection is not private" scary error, where in fact I'd love if they'd get redirected to HTTP.
If I add:
server {
listen 443 default_server;
server_name _;
return 301 http://$host$request_uri;
}
Then this works, but the second server block stops working and I get that the server is unable to handle the request.
How can I do this?