我正在使用 nginx 设置一个 debian 服务器,我希望能够使用 HTTPS 提供我的网络服务。我还在学习,我发现自己迷失在 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 建立的每个网络连接并将其转发到正确的子域服务。我希望能够为我的每个子域创建一个文件及其服务器 block ,这将允许我明确地说我是否想要该特定域的 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 部署一个 flask 应用程序:
server {
listen 80;
server_name IP_OF_MY_SERVER;
ssl on;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/user1/website/website.sock;
}
}
现在我想为我的其他网络服务创建子域,我所做的是在启用站点的情况下创建一个新的主机文件,例如传输网络用户界面(我想要它没有 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;
}
}
还有另一个 flask 应用程序(我想要它与 SSL):
server {
listen 80;
server_name sub2.domain.com;
ssl on;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/user2/flaskapp2/flaskapp2.sock;
}
}
不幸的是,我尝试的所有操作都导致了 HSTS 错误或其他类型的错误。也许我的用例是不可能的。如果有人能向我解释我做错了什么,我将不胜感激。
最佳答案
第一个问题。 letsencrypt 证书不能使用通配符。
关于ssl - 将 Let's Encrypt 与由 Nginx 通配符处理的子域一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44613236/