2016-09-03 15 views
0

wwwとnon-wwwから私のWebサイトのhttps-non-www URIへのリダイレクトは機能しません。Nginx - 301はwwwとnon-wwwをhttps-non-wwwにリダイレクトしません

ここに私のサーバブロック:

server { 
     listen   80; 
     listen   [::]:80; 
     server_name  gfelot.xyz www.gfelot.xyz; 
     return   301 https://gfelot.xyz$request_uri; 
} 

server { 
     listen   443 ssl http2 default_server; 
     listen   [::]:443 ssl http2 default_server; 
     include   snippets/ssl-gfelot.xyz.conf; 
     include   snippets/ssl-params.conf; 

     server_name  gfelot.xyz; 

     access_log  /var/log/nginx/gfelot.xyz.access.log; 
     error_log  /var/log/nginx/gfelot.xyz.log; 

     root /var/www/html; 
     index index.html index.htm 

     error_page  404 /404.html; 
     error_page  500 502 503 504 /50x.html; 

     location = /50x.html { 
       root /usr/share/nginx/html; 
     } 

     location ~* \.css$ { 
       access_log off; 
       expires 1M; 
       add_header Pragma public; 
       add_header Cache-Control public; 
       add_header Vary Accept-Encoding; 
     } 
} 

は、SSL-gfelot.xyz.confを含める:

ssl_certificate /etc/letsencrypt/live/gfelot.xyz/fullchain.pem; 
ssl_certificate_key /etc/letsencrypt/live/gfelot.xyz/privkey.pem; 

は、SSL-params.confを含める:

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
ssl_prefer_server_ciphers on; 
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; 
ssl_ecdh_curve secp384r1; 
ssl_session_cache shared:SSL:10m; 
ssl_session_tickets off; 
ssl_stapling on; 
ssl_stapling_verify on; 
resolver 8.8.8.8 8.8.4.4 valid=300s; 
resolver_timeout 5s; 
# Disable preloading HSTS for now. You can use the commented out header line that includes 
# the "preload" directive if you understand the implications. 
#add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; 
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains"; 
add_header X-Frame-Options SAMEORIGIN; 
add_header X-Content-Type-Options nosniff; 

ssl_dhparam /etc/ssl/certs/dhparam.pem; 

答えて

0
server { 
    listen   80; 
    listen   [::]:80; 
    server_name  gfelot.xyz www.gfelot.xyz; 
    return   301 https://gfelot.xyz$request_uri; 
} 

server { 
    listen   443; 
    server_name  gfelot.xyz; 

    ssl on; 
    ssl_certificate < your ssl file ssl-xyx.crt path>; 
    ssl_certificate_key <ssl keyfile.key path>; 
    access_log  /var/log/nginx/gfelot.xyz.access.log; 
    error_log  /var/log/nginx/gfelot.xyz.log; 

    root /var/www/html; 
    index index.html index.htm 

    error_page  404 /404.html; 
    error_page  500 502 503 504 /50x.html; 

    location = /50x.html { 
      root /usr/share/nginx/html; 
    } 

    location ~* \.css$ { 
      access_log off; 
      expires 1M; 
      add_header Pragma public; 
      add_header Cache-Control public; 
      add_header Vary Accept-Encoding; 
    } 
} 
+0

私がかもしれませんあなたが私のインクルードに持っているファイルを表示することを忘れないでくださいが、それはssl certifファイルです。 投稿を編集します。 – Ragnar

+0

あなたの正しいsslパスを設定してください&同様に私の投稿のように –

+0

私はインクルードの中に私のファイルのパスを入れます。それで何も変わらない。 – Ragnar

関連する問題