2017-06-23 96 views
0

我有一个Rails应用程序,一切正常。Rails - Puma - Nginx:如何将所有内容重定向到https://www.example.com?

我的nginx的配置文件:

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 

} 

我的问题:如何重定向所有到https://www.example.com中?

通过以上配置,它可以重定向到https://示例.com,而不是到https:任何答案//www.example.com中

感谢。

回答

0

更改此:

server_name enziin.com; 

这样:以上

server_name enziin.com www.example.com; 

使nginx的服务在两台主机。目前它仅映射为enzinn.com。在此之后,您现有的配置也应该为www.example.com,并将开始重定向到其相当于https

(请确保www.example.com的DNS记录指向您的nginx)

相关问题