ssl - NGINX + 让我们加密 : Could not automatically find a matching server block

标签 ssl nginx lets-encrypt nginx-config certbot

我正在 Ubuntu 18.04 服务器上发布一个使用 Python Pyramid 制作的网站。该网站在 HTTP 上正常运行,现在我试图通过遵循 this article 使其在 HTTPS 上运行但是在尝试安装时,我收到此消息:

IMPORTANT NOTES:
 - Unable to install the certificate
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/dev.anything.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/dev.anything.com/privkey.pem
   Your cert will expire on 2019-03-17. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew" 

这是我的配置文件,位于 /etc/nginx/sites-available/snow_service.nginx :
server {
    listen 80;
    listen 443 ssl;
    server_name dev.anything.com
    server_tokens off;
    ssl_certificate /etc/letsencrypt/live/dev.anything.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dev.anything.com/privkey.pem;

    charset utf-8;
    client_max_body_size 1M;

    location /static {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;

        alias /webapps/englobe_snow_pyramid_rest_api/pyramid_rest_api/static;
        expires 1d;
    }
    location / {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;

        try_files $uri @yourapplication;
    }
    location @yourapplication {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;

        server_tokens off;
        include uwsgi_params;
        proxy_set_header Host $host;
        proxy_set_header real_scheme $scheme;
        proxy_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:8999;
    }
}

我也尝试用域名重命名文件,但效果不佳。
我手动放置的 ssl 证书的路径,因为我在 Stack Overflow 的另一个答案中看到了它。

我错过了什么?谢谢你的帮助

最佳答案

这是解决方案:
我正在更改 sites-available 中的文件文件夹而不更改 sites-enabled 处的文件文件夹。这是最终的文件内容:

server {
    listen 80 default_server;
    server_name dev.anything.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name elglobe_snow_service
    server_tokens off;

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

    charset utf-8;
    client_max_body_size 1M;

    location /static {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;

        alias /webapps/englobe_snow_pyramid_rest_api/pyramid_rest_api/static;
        expires 1d;
    }
    location / {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;

        try_files $uri @yourapplication;
    }
    location @yourapplication {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;

        server_tokens off;
        include uwsgi_params;
        proxy_set_header Host $host;
        proxy_set_header real_scheme $scheme;
        proxy_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:8999;
    }
}

关于ssl - NGINX + 让我们加密 : Could not automatically find a matching server block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53824640/

相关文章:

ssl - NGINX 不会监听 443 端口

node.js - 让我们加密 SSL 无法从 "Error: EACCES: permission denied, open '/etc/letsencrypt/live/domain.net/privkey.pem 开始'”

android - java.security.cert.CertPathValidatorException : Trust anchor for certification path not found in React-Native

java - TLS-Package 后的神秘字节

c# - 跳过 SSL TCP 连接的验证过程

ssl - 如何使用 nginx 从 http 负载均衡器迁移到 https 负载均衡器

Nginx 和处理无扩展名的文件

docker - 蓝铜矿容器不暴露 ssl

Apache Wamp [错误] (20024)给定路径格式错误或包含无效字符

ssl - 安装了 SSL 证书,但仍然暴露于中间人攻击