【问题标题】:NGINX + Let's encrypt: Could not automatically find a matching server blockNGINX + Let's encrypt:无法自动找到匹配的服务器块
【发布时间】:2019-05-18 09:01:12
【问题描述】:

我正在 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 的另一个答案中看到了它。

我错过了什么?感谢您的帮助

【问题讨论】:

    标签: ssl nginx lets-encrypt nginx-config certbot


    【解决方案1】:

    解决方法如下: 我正在更改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;
        }
    }
    

    【讨论】:

    • 具体路径是什么?
    【解决方案2】:

    sites-enabled 中的文件应该只是指向sites-available 中“真实”文件的链接。 您应该只编辑可用站点中的那些,然后运行

    cd /etc/nginx/sites-enabled ln -s ../sites-available/your-site.conf

    启用该网站。

    如果您想禁用该站点,您只需删除启用站点中的链接即可。

    【讨论】:

    • 就我而言,sites-available/ 中有 default 文件。我刚刚按照上面的建议在sites-enabled/ 中创建了指向该文件的链接,然后运行sudo certbot --nginx,它终于奏效了。
    • 路径的顺序应该是文件后跟目录我相信,即ln -s ../sites-available/your-site.conf /etc/nginx/sites-enabled
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 2022-08-10
    • 1970-01-01
    相关资源
    最近更新 更多