【问题标题】:Using Let's Encrypt with subdomains handled by Nginx's wildcard将 Let's Encrypt 与 Nginx 通配符处理的子域一起使用
【发布时间】:2017-11-20 15:31:51
【问题描述】:

我正在使用 nginx 设置一个 debian 服务器,并且我希望能够使用 HTTPS 提供我的 Web 服务。我还在学习,发现自己迷失在 nginx+let's encrypt 配置中。

第一个问题:

感谢 nginx (sub.domain.com),我是否必须向 certbot 提供我要创建的所有子域

certbot certonly -a webroot --webroot-path=/var/www/html -d domain.com -d sub1.domain.com -d sub2.domain.com

或者我可以只提供我的主域(domain.com),它会生成一组证书,感谢 nginx,我可以在以后使用这些证书

certbot certonly -a webroot --webroot-path=/var/www/html -d domain.com
第二个问题:

我按照 Nginx + Let's Encrypt + Debian DigitalOcean 教程设置了我的服务器。

我访问了我的域 DNS,并为我的 nginx 服务器提供了一个通配符,以便它处理子域。

  A      domain.com     SERVER_IP
CNAM    *.domain.com    domain.com

并且我希望能够在启用站点的文件夹中创建一个默认文件,该文件处理与端口 80 建立的每个网络连接并将其转发到正确的子域服务。而且我希望能够为我的每个子域创建一个带有其服务器块的文件,这将允许我明确说明我是否想要该特定域的 SSL。

我的默认文件现在看起来像这样:

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name domain.com www.domain.com;
        return 301 https://$server_name$request_uri;
}

server {

        # SSL configuration

        listen 443 ssl http2 default_server;
        listen [::]:443 ssl http2 default_server;

        ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.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";
        ssl_ecdh_curve secp384r1;
        ssl_session_cache shared:SSL:10m;
        ssl_session_tickets off;
        ssl_stapling on;
        ssl_stapling_verify on;
        resolver 8.8.8.8 8.8.4.4 valid=300s;
        resolver_timeout 5s;
        # Disable preloading HSTS for now.  You can use the commented out header line that includes
        # the "preload" directive if you understand the implications.
        #add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
        add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
        add_header X-Frame-Options DENY;
        add_header X-Content-Type-Options nosniff;

        ssl_dhparam /etc/ssl/certs/dhparam.pem;

        #root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name domain.com;

        location / {
                include uwsgi_params;
                uwsgi_pass unix:/home/user1/website/website.sock;
        }       


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

我在另一个文件中有一个主机,它使用我的主域来部署带有 ssl 的烧瓶应用程序:

server {
    listen 80;
    server_name IP_OF_MY_SERVER;

    ssl on;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/user1/website/website.sock;
    }
}

现在我想为我的其他 Web 服务创建子域,我要做的是在启用站点的情况下创建一个新的主机文件,例如传输 web ui(我希望它没有 SSL):

server {
        listen 80;
        server_name sub1.domain.com;

        ssl off;

        location / {
                proxy_pass      http://localhost:9091/;
        }

        location /transmission {
                proxy_pass      http://localhost:9091/transmission;
        }
}

还有另一个烧瓶应用程序(我想要使用 SSL):

server {
    listen 80;
    server_name sub2.domain.com;

    ssl on;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/user2/flaskapp2/flaskapp2.sock;
    }
}

不幸的是,我尝试的所有操作都导致了 HSTS 错误或其他类型的错误。也许我的用例是不可能的。如果有人能向我解释我做错了什么,我将不胜感激。

【问题讨论】:

标签: ssl nginx https lets-encrypt


【解决方案1】:

关于你的第一个问题。 letencrypt 证书不能使用通配符。

【讨论】:

猜你喜欢
  • 2016-12-06
  • 1970-01-01
  • 2017-06-05
  • 2021-05-06
  • 2016-12-18
  • 2017-01-18
  • 1970-01-01
  • 1970-01-01
  • 2019-05-17
相关资源
最近更新 更多