2017-01-02 13 views
0

何か入力するたびにSSL(https)とwww( "https:// www.xyz.com")をブラウザに適用しようとしていますドメイン( "xyz.com")のメインドメインでnginxのサブドメインではなくSSLとwwwを適用

私はサブドメインも持っています。私はサブドメインに "www"を適用したくありません(これはうまくいきます)。

ブラウザに「https:// xyz.com」と入力すると、ngingxはwww(「https:// www.xyz.com」)を入力しない限り、すべてがうまくいっていますが、 "https:// xyz.com"のみ。私が間違っているのどこ

server { 
    listen 443; 
    server_name xyz.com *.xyz.com; 
    ssl on; 
    ssl_certificate /etc/nginx/ssl/xyz.crt; 
    ssl_certificate_key /etc/nginx/ssl/*.xyz.com.key; 
    ssl_session_timeout 5m; 
    ssl_protocols SSLv3 TLSv1; 
    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP; 
    ssl_prefer_server_ciphers on; 
    location/{ 
     proxy_pass http://127.0.0.1:8069; 
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; 
     proxy_buffer_size 128k; 
     proxy_buffers 16 64k; 
     proxy_redirect off; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     location ~* /web/static/ { 
      proxy_buffering off; 
      proxy_pass http://127.0.0.1:8069; 
     } 
    } 
} 

server { 
    listen 80; 
    server_name xyz.com; 
    add_header Strict-Transport-Security max-age=2592000; 
    rewrite ^/.*$ https://www.$host$request_uri? permanent; 
} 

server { 
    listen 80; 
    server_name *.xyz.com; 
    add_header Strict-Transport-Security max-age=2592000; 
    rewrite ^/.*$ https://$host$request_uri? permanent; 
} 

は親切に私を導く:

サイト-利用可能の設定ファイルを以下に示します。

ありがとうございます。

答えて

1

オプションを443ポートのsslサーバーブロックに移動します。

server { 
    listen 443; 
    add_header Strict-Transport-Security max-age=2592000; 
    # rest configs 
} 

変更HTTP 80ブロック

server { 
    listen 80; 
    listen [::]:80; 
    server_name example.com; 
    return 301 https://www.example.com$request_uri; # permenent redirect 
} 

へNOTE:設定をnginxのために行われた変更は、私が通り試したことが sudo service nginx reload

+0

を必要とするのUbuntuでの変更を適用するためにnginxのプロセスにreload信号を必要としますあなたの提案は動作していません。 ブラウザに「https:// xyz.com」と入力すると、wwwは適用されません。 –

+0

まだ書き換えブロックがありますか?または返された301と置き換えられます。また、プライベートブラウザのウィンドウでチェックします –

+0

書き換えブロックをコメントしたり削除したりして、301を追加しました。 はい、プライベートウィンドウもチェックインしました。 –

関連する問題