2017-06-23 6 views
0

私はRailsアプリを持っています。すべてうまくいきます。Rails - Puma - Nginx:すべてをhttps://www.example.comにリダイレクトする方法は?

私のnginxのconfigureコンファイル:

upstream puma-enziin { 
    server unix:///home/kevin/websites/enziin/shared/tmp/sockets/enziin-puma.sock; 
} 

server { 
    listen 80; 
    server_name enziin.com; 

    root /home/kevin/websites/enziin/current/public; 

    access_log /home/kevin/websites/enziin/current/log/nginx.access.log; 
    error_log /home/kevin/websites/enziin/current/log/nginx.error.log info; 

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

    # Some browsers still send conditional GET requests if there's a 
    # Last-Modified header or an ETag header even if they haven't 
    # reached the expiry date sent in the Expires header. 
    add_header Last-Modified ""; 
    add_header ETag ""; 
    break; 
    } 

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

    proxy_set_header X-Forwarded-Proto $scheme; 

    proxy_set_header Host $http_host; 
    proxy_redirect off; 

    proxy_pass http://puma-enziin; 
    } 

    error_page 500 502 503 504 /500.html; 
    client_max_body_size 10M; 
    keepalive_timeout 10; 

    listen 443 ssl; # managed by Certbot 
    ssl_certificate /etc/letsencrypt/live/enziin.com-0001/fullchain.pem; # managed by Certbot 
    ssl_certificate_key /etc/letsencrypt/live/enziin.com-0001/privkey.pem; # managed by Certbot 
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot 

    if ($scheme != "https") { 
     return 301 https://$host$request_uri; 
    } # managed by Certbot 

} 

私の質問://www.example.com:どのようにhttpsにすべてをリダイレクトするには?上記のconfigureで

、それはHTTPSにリダイレクトすることができます任意の答えを//www.example.com

ありがとう://example.comではなく、httpsに。これに

server_name enziin.com; 

server_name enziin.com www.example.com; 

上記の二つのホストに奉仕するのnginxになり、この

答えて

0

変更。現在のところ、それ自体はenzinn.comのためにのみマッピングされています。この後、既存の設定もwww.example.comで動作し、同等のhttpsにリダイレクトされます。

(www.example.comのDNSレコードがあなたのnginxを指していることを確認してください)

関連する問題