So I have two domains:

```
example.com
example.ca

```

This is a docker container running nginx and I am trying to accomplish http to https redirect and www to non-www redirect.

Docker on the host is bound to port 80 and 443. To be clear traffic works to and from the server without issue.

The issue is the www redirects seem to be ignored.

When a user goes to <http://www.example.com> I expect them to be redirected to <https://example.com>

What happens is they are actually redirected to <https://www.example.com>

So the https redirection works 100% of the time but for some reason nginx fails to perform the redirect without www

It's worth noting we are using CloudFlare to replace our self signed certificates. So maybe CloudFlare is causing the issue?

Here are my redirects.

```
    server {
        listen 8080;
        listen 8443;
        server_name www.example.com;
        return 301 https://$host$request_uri?$args;
    }

    server {
        listen 8080;
        listen 8443;
        server_name www.example.ca;
        return 301 https://$host$request_uri?$args;
    }

#   Force http to https
    server {
        listen 8080;
        server_name example.com;
        return 301 https://$host$request_uri?$args;
    }

    server {
        listen 8080;
        server_name example.ca;
        return 301 https://$host$request_uri?$args;
    }

```