nginx http到https重定向

nginx http到https重定向,http,nginx,Http,Nginx,我很难重定向到https。www.example.net运行良好。但是,example.com不会重定向到https。我尝试了很多配置。下面是我目前的一个 server { server_name example.net www.example.net; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /path/to/stat

我很难重定向到https。www.example.net运行良好。但是,example.com不会重定向到https。我尝试了很多配置。下面是我目前的一个

server {
    server_name example.net www.example.net;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /path/to/static;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
        proxy_connect_timeout 75s;
        proxy_read_timeout 300s;
        proxy_request_buffering off;
        proxy_buffering off;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = www.example.net) {
        return 301 https://www.$host$request_uri;
    } # managed by Certbot

    if ($host = example.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;
    server_name  example.net www.example.net;
    return 404; # managed by Certbot


}