2016-10-13 4 views
0

私はカップルのすべてのドメインとバリエーションが現在のプライマリの場所を指していることを確認するための場所で再指示があります。Nginxは適切に再指示ではないときに、ユーザーのタイプのhttps://

#redirects www 
server { 
    server_name www.blah.net; 
    return 301 https://blah.org$request_uri; 
} 

server { 
    server_name www.blah.co; 
    return 301 https://blah.org$request_uri; 
} 

#redirects co and net to org 
server { 
    server_name blah.co; 
    return 301 https://blah.org$request_uri; 
} 

server { 
    server_name blah.net; 
    return 301 https://blah.org$request_uri; 
} 

#redirects all traffic to https 
server { 
    listen *:80 default_server; 

    location/{ 
     return 301 https://$host$request_uri; 
    } 
} 

#main server 
server { 
    listen *:443 ssl; 
    ssl on; 

    ssl_certificate /etc/letsencrypt/live/www.blah.org/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/www.blah.org/privkey.pem; 

    root /home/blah/www; 
    index index.html index.htm; 

    server_name blah.org blah.co blah.net; 
} 

問題は、私たちのことですトップのGoogle検索結果にはhttps://blah.coを指すリンクがあり、クリックすると証明書エラーが表示されます。私は問題が何であるか理解しています。リダイレクトを修正する方法がわからないので、httpsまたはhttps://blah.coを含むリンクをクリックするとhttps://blah.orgに解決されます。

+0

ポイントはそれを避けるためです@AlexeyTen 'blah.co' –

+0

のための有効な証明書を取得する - と、有効な証明書を持っている唯一のサイトであるblah.orgですべてのトラフィックをリダイレクトします。 – redband

+0

httpsの要点はそれを避けることができないようにすることです –

答えて

0

私はこれがうまくいくと思います。最初のブロックはhttps://blah.orgではないトラフィックを捕捉し、リダイレクトする必要があります。 2番目のサーバーブロックはblah.orgドメインのみを処理します。

# redirects all non-.org traffic to https 
server { 
    listen *:80 default_server; 
    listen *:443 ssl; 

    ssl_certificate /etc/letsencrypt/live/www.blah.org/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/www.blah.org/privkey.pem; 

    server_name _; 

    location/{ 
     return 301 https://blah.org$request_uri; 
    } 
} 

#main server 
server { 
    listen *:443 ssl; 
    ssl on; 

    ssl_certificate /etc/letsencrypt/live/www.blah.org/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/www.blah.org/privkey.pem; 

    root /home/blah/www; 
    index index.html index.htm; 

    server_name blah.org; 
} 
+0

これはまだ有効な証明書が必要です –

+0

@AlexeyTen私はあなたに反対していませんが、私はこれをプロダクション環境でやっているのと逆です。 301以外のすべての '非https'トラフィックをhttps://www.domain.comにリダイレクトし、ワイルドカードSSL証明書のみを取得します。 'http:// ip-address'でも正しくリダイレ​​クトされます。 – miah

関連する問題