【问题标题】:How to configure multiple domains with letsencrypt on nginx如何在 nginx 上使用letsencrypt配置多个域
【发布时间】:2016-11-07 06:38:12
【问题描述】:

我在尝试为 2 个域配置 SSL 时遇到了一些问题(在 link 之后)。请帮我!

我的上下文是:

  • 我的服务器上有 2 个域:example.comtest.com

我想为以上 2 个域配置 SSL。这是配置: 档案/etc/nginx/sites-available/example

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


server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;

    root /home/user1/example-com;
    index index.php index.html index.htm;

    server_name example.com www.example.com;

    location ~ ^/index.php/.*$ {
            try_files $uri $uri/ /index.php?$args;
    }

    access_log /var/log/nginx/example-access.log;
    error_log /var/log/nginx/example-error.log;

    location ~ /.well-known {
        allow all;
    }   

    # other configurations
}

文件/etc/nginx/sites-available/test

server {
    listen 80;
    listen [::]:80;
    server_name test.com www.test.com;
    return 301 https://$server_name$request_uri;
}


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;

#    include snippets/ssl-test.com.conf;    # I tried with other file but it didn't work
#    include snippets/ssl-params.conf;

    root /home/user1/test-tk;
    index index.php index.html index.htm;

    server_name test.com www.test.com;

    # Make site accessible from http://localhost/
    # server_name test.com;
    location ~ ^/index.php/.*$ {
            try_files $uri $uri/ /index.php?$args;
    }

    access_log /var/log/nginx/test-access.log;
    error_log /var/log/nginx/test-error.log;

    location ~ /.well-known {
        allow all;
    }   

    # other configurations  
}

重启nginx后没有任何错误。

我可以使用https://example.com/ 访问,第一个站点一切正常。但是对于第二个站点,它不起作用。访问链接 https://test.com/ 时,我收到警告“您的连接不是私有的”。

【问题讨论】:

  • 显然您不能在test.com 上使用example.com 的证书。所以你需要调查为什么ssl-test.com.conf 不起作用。文件是否丢失,是否指向错误文件,证书文件是否丢失?
  • 谢谢@richard-smith。我使用了以下 2 个命令:sudo letsencrypt certonly -a webroot --webroot-path=/home/user1/example-com -d example.com -d www.example.comsudo letsencrypt certonly -a webroot --webroot-path=/home/user1/test-tk -d test.com -d www.test.com,但它仅适用于 example.com,不适用于 test.com。没有任何错误,请帮忙
  • nginx 和letsencrypt 有同样的问题

标签: ssl nginx lets-encrypt


【解决方案1】:

代替行:

include snippets/ssl-example.com.conf;

使用站点特定的配置(或替换ssl-example.com.conf的内容):

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

ssl-params.conf 应该包含这样的内容:

   ssl on;
   ssl_session_timeout 5m;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
   ssl_prefer_server_ciphers on;
   ssl_session_cache shared:SSL:10m;

(不一定是完美的配置,但应该可以胜任)。尤其是ssl on;这一行很重要。

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 2018-05-21
    • 2017-03-25
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    相关资源
    最近更新 更多