2016-09-03 3 views
0

www 및 non-www에서 웹 사이트의 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

관련 문제