I have been working with this for hours and still can't see what's the problem with my config. Kindly see below.

**/etc/nginx/sites-enabled/default**

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

server {
    listen 443 ssl;
    server_name example.com www.example.com;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    ssl_ciphers 'ECDHE-RSA-AES128...;

    location / {
        include    uwsgi_params;
        uwsgi_pass    unix:/my_socket/site.sock;
    }    

    location /static/ {
        alias /my_static/location/;
    }

    location /media  {
        alias /my_media/location/;
    }

    location ~ /.well-known{
        allow all;
    }
    return 301 https://www.example.com$request_uri;
}

```

When I try to access *example.com*, *www.example.com* it redirects to **<https://www.example.com>**(which is what I want) but the page is not working unless I remove the last line code below.

```
return 301 https://www.example.com$request_uri;

```

After removing the line above, all links are working well but not redirecting to **www**.

---

Machine:

* Ubuntu 14.04
* nginx/1.4.6 (Ubuntu) with uWSGI
* DJango 1.8.4 running in Google Cloud Platform (Compute Engine)