在同一个nginx服务器上使用SSL的两个node.js域 - 重复443的监听选项

时间:2018-04-20 09:24:40

标签: node.js ubuntu ssl nginx digital-ocean

我已经在我的DigitalOcean Droplet中设置了两个Web应用程序,并且我尝试使用SSL加密在不同的域上运行这两个应用程序。

如果我只使用其中一个域,我可以确认一切正常,当我尝试同时运行这两个域时会发生错误。

nginx -t
duplicate listen options for [::]:443 in /etc/nginx/sites-enabled/hello.com:26

/etc/nginx/sites-avilable/hello.com

server {
    server_name hello.com www.hello.com;

    location / {
            proxy_pass http://localhost:4000;
            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;
    }

    listen [::]:443 ssl ipv6only=on default_server; # managed by Certbot
    listen 443 ssl default_server; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/hello.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/hello.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}

server {
        if ($host = www.hello.com) {
                return 301 https://$host$request_uri;
        } # managed by Certbot


    if ($host = hello.com) {
            return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 default_server;
    listen [::]:80 default_server;

    server_name hello.com www.hello.com;
    return 404; # managed by Certbot
}

/etc/nginx/sites-available/example.com

server {
    server_name example.com www.example.com;

    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;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}

server {
        if ($host = www.example.com) {
                return 301 https://$host$request_uri;
        } # managed by Certbot


    if ($host = example.com) {
            return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;
    return 404; # managed by Certbot
}

我该怎么做才能避免此错误?非常感谢nginx文件的进一步改进。

我使用了以下指南:

如何设置Nginx服务器块:https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts

如何在Ubuntu 16.04上设置生产的Node.js应用程序:https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

如何使用Ubuntu 16.04上的加密来保护Nginx: https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

1 个答案:

答案 0 :(得分:1)

问题是ipv6only=on,只能在according to the documentation时指定一次。

无论如何,默认值为on,因此可以安全地删除该选项。