Letsencrypt在同一个DigitalOcean Droplet上的node和rails app上使用SSL。适用于rails而不适用于节点

时间:2016-03-20 18:00:17

标签: ruby-on-rails node.js ssl nginx lets-encrypt

我有两个应用程序,一个是rails应用程序,它使用Let加密SSL和nginx作为服务器。它部署在数字海洋上。 我还添加了一个简单的节点应用程序(用于我的rails应用程序的补充功能),使用Express构建,可以侦听端口8080。

我希望我的节点应用程序使用与我的rails应用程序相同的SSL证书。 如何通过使用nginx进行配置来实现?或者有更好的方法来实现这一目标吗?

这是我的nginx配置文件。

server {
                listen 443 ssl;
            server_name mydomain.com www.mydomain.com;

        ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

        passenger_enabled on;
        rails_env    production;
        root         /home/deploy/mydomain/current/public;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

server {
    listen 80;
    server_name mydomain.com;
    return 301 https://$host$request_uri;
}

1 个答案:

答案 0 :(得分:2)

您需要生成2个证书,每个应用一个,指定不同的端口或子域。然后你需要2个不同的nginx conf

server {
    listen 443 ssl;
    server_name abc.xyz www.abc.xyz;
    ssl_certificate /etc/letsencrypt/live/abc.xyz/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/abc.xyz/privkey.pem;
    location / {
        root  /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;
    }
}


server {
    listen 443 ssl;
    server_name api.abc.xyz;
    ssl_certificate /etc/letsencrypt/live/api.abc.xyz/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.abc.xyz/privkey.pem;
    location / {
        proxy_pass http://localhost:3000/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}