nginx catchall interfering with wildcard

Viewed 10

I want to redirect www (and possibly other subdomains) to my https domain. So I wrote a rule

server {
    listen 80;
    server_name *.example.com example.com;
    return 301 https://example.com$request_uri;
}

This didn't work until I removed my catch all entry (pasted below). I want to drop or ignore request from no host or host that don't belong to my machine. How do I get the two rules to play nice with eachother?

server {
    listen          80 default_server;
    listen          [::]:80 default_server;
    listen          443 default_server;
    listen          [::]:443 default_server;
    server_name     _;

    include snippets/snakeoil.conf;

    return          444;
}
0 Answers
Related