Nginx перенаправляет все www не на www, а http на https - PullRequest
0 голосов
/ 02 июня 2018

Я использую nginx, let's encrypt и пытаюсь перенаправить все с http и www на один маршрут - https://example.com.Все работает, кроме https://www.example.com.Это не перенаправляет.Что я делаю неправильно?Мой код ниже.

server {

    root /var/www/example.com;
    index index.html index.php index.htm;

    server_name example.com www.example.com;


    location ~* ^(?!/phpmyadmin/).+\.(jpg|jpeg|gif|png|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|xml|docx|xlsx)$ {
            access_log off;
            expires 30d;
    }


    location ~ /\.ht {
            deny all;
    }



    location / {
            proxy_pass http://127.0.0.1:81/;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-for $remote_addr;
            proxy_set_header Host $host;
            proxy_connect_timeout 300;
            proxy_send_timeout 300;
            proxy_read_timeout 300;
            proxy_redirect off;
            proxy_set_header Connection close;
            proxy_pass_header Content-Type;
            proxy_pass_header Content-Disposition;
            proxy_pass_header Content-Length;
    }



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/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.com) {
         return 301 https://example.com$request_uri;
    } # managed by Certbot


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



    listen 80;

    server_name example.com www.example.com;
    return 404; # managed by Certbot




    }
...