// Personal website of Chris Smith

Nginx » Redirect to canonical domain

Instead of complex rules to redirect certain requests, just add a separate server block:

server {
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
}

Or add a default server block to catch everything not explicitly dealt with:

server {
    server_name _;
    listen 80 default_server;
    return 301 $scheme://example.com$request_uri;
}