Nginx HTTPS www para não redirecionar o problema de www

2

Estou tendo alguns problemas redirecionando de HTTPS www para HTTPS não-www com minha configuração nginx. Estou seguindo as instruções fornecidas em ( Remover "www" e redirecionar para "https" com nginx ).

Neste momento, o seguinte trabalho:

Mas isso não acontece:

Acabo recebendo o "Welcome to nginx!" página. Eu não tenho nenhum outro arquivo de configuração do nginx em /sites-enabled . Alguma idéia de por que isso pode estar fazendo isso?

Meu arquivo de configuração está abaixo.

upstream redemfit {
    server unix:/srv/redemfit/run/gunicorn.sock fail_timeout=0;
}

server {
    listen         80;
    server_name    www.redemfit.com redemfit.com;
    rewrite        ^ https://redemfit.com$request_uri? permanent;
}

server {
    listen 443;
    ssl on;
    ssl_certificate /etc/ssl/private/redemfit-bundle.crt;
    ssl_certificate_key /etc/ssl/private/redemfit.key;
    ssl_protocols SSLv3 TLSv1;
    ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
    server_name www.redemfit.com
    rewrite ^ https://redemfit.com$request_uri? permanent;
}

server {
    listen   443;

    ssl on;
    ssl_certificate /etc/ssl/private/redemfit-bundle.crt;
    ssl_certificate_key /etc/ssl/private/redemfit.key;
    ssl_protocols SSLv3 TLSv1;
    ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;

    server_name redemfit.com;

    client_max_body_size 4G;

    access_log /srv/redemfit/logs/nginx-access.log;
    error_log /srv/redemfit/logs/nginx-error.log;

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    location /static {
        auth_basic off;
        root /srv/redemfit/static_collected;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        if (!-f $request_filename) {
            proxy_pass http://redemfit;
            break;
        }
    }
}
    
por Jack Slingerland 08.10.2014 / 14:02

1 resposta

5

Tente remover completamente o bloco HTTPS server {} para www.redemfit.com e adicione o código abaixo no bloco principal HTTPS:

if ($host = 'www.redemfit.com' ) {
          rewrite  ^/(.*)$  https://redemfit.com/$1  permanent;
}

Espero que, ao escrever a postagem, você tenha cometido um erro de digitação:

server { listen 443; ssl on; ssl_certificate /etc/ssl/private/redemfit-bundle.crt; ssl_certificate_key /etc/ssl/private/redemfit.key; ssl_protocols SSLv3 TLSv1; ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM; server_name www.redemfit.com # <- Missing semicolon rewrite ^ https://redemfit.com$request_uri? permanent; }

    
por 08.10.2014 / 14:06

Tags