2017-04-11 12 views
0

www.example.comの代わりにすべてのURLをexample.comにリダイレクトしようとしています。 www.example.comと入力してhttps://domain.comへのリダイレクトを入力すると、正常に動作しています。しかし、https://www.example.comと入力するとhttps://www.example.comに行きますが、https://example.comにリダイレクトしようとしています。私は同様の質問にいくつかの解決策をたどったが、うまくいかなかった。以下は私のnginx設定ファイルです。wwwからnonwwwへのリダイレクトはnginxのhttpsで動作しません

upstream puma { 
    server unix:///home/deploy/apps/myprod/shared/tmp/sockets/myprod-puma.sock; 
} 
server { 
    listen 80; 
    listen [::]:80; 
    server_name example.com; 
    return 301 https://$server_name$request_uri; 
} 

server { 
    #listen 80 default_server deferred; 
    #listen 80; 
    listen 443 default ssl; 

    server_name domain.com; 

    ssl_certificate /etc/nginx/ssl/domain.com.chained.crt; 
    ssl_certificate_key /etc/nginx/ssl/domain.key; 


    root /home/deploy/apps/myprod/current/public; 
    access_log /home/deploy/apps/myprod/current/log/nginx.access.log; 
    error_log /home/deploy/apps/myprod/current/log/nginx.error.log info; 

    #location ^~ /assets/ { 
    #gzip_static on; 
    #expires max; 
    #add_header Cache-Control public; 
    #} 

    location ^~ /(assets|fonts|swfs|images)/ { 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
    } 

    try_files $uri/index.html $uri @puma; 
    location @puma { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 

    proxy_pass http://puma; 
    } 
} 

誰か私はこの非WWWが

+0

[この回答](http://stackoverflow.com/questions/43081780/dns-records-redirect-www-to-non-www/43089681#43089681)が役立ちます。 –

答えて

1

このserverブロックコードを使用してみてくださいリダイレクト達成するために行う必要がありますどのような変化を伝えることができますしてください:

server { 
    listen 80; 
    listen 443; 
    server_name www.example.com; 
    return 301 https://$server_name$request_uri; 
} 

はそれが役立つだろうと思います。

関連する問題