【问题标题】:nginx as https proxy, but want to intercept one static path for Let's Encrypt /.well-known challengesnginx 作为 https 代理,但想为 Let's Encrypt /.well-known 挑战截取一个静态路径
【发布时间】:2017-04-19 22:41:22
【问题描述】:

有很多关于使用 ngix 作为反向代理的资料,它作为我需要使用的奇怪 Web 服务器应用程序的基本代理对我来说效果很好。我什至有重定向,所以 http 被重定向到 https。

server {
    listen         80;
    server_name    <my server>;
    return         301 https://$server_name$request_uri;
}

server {
    listen         443 ssl;
    server_name    <my server>;


    # add Strict-Transport-Security to prevent man in the middle attacks
    add_header Strict-Transport-Security "max-age=31536000"; 

    ssl on;
    ssl_certificate cert1.crt.pem;
    ssl_certificate_key cert1.key.pem;
    ssl_session_cache shared:SSL:10m;

    location / {
        proxy_pass http://localhost:81; # my existing apache instance
        proxy_set_header Host $host;
    }

现在我有一个新的皱纹。我想选择一条特定的路径,而不是将其转发到主服务器应用程序。我需要这样做以添加一些 Let's Encrypt 质询响应。每当传入的 url 是 http:///.well-known/acme-challenge/ 时,我想使用静态 nginx 路径而不是转发到主服务器。

有什么想法吗?我尝试在位置目录中添加,但没有奏效。

server {
    listen         80;
    server_name    video.maritimeopscorp.com;
    return         301 https://$server_name$request_uri;
}

server {
    listen         443 ssl;
    server_name    video.maritimeopscorp.com;


    # add Strict-Transport-Security to prevent man in the middle attacks
    add_header Strict-Transport-Security "max-age=31536000"; 

    ssl on;
    ssl_certificate cert1.crt.pem;
    ssl_certificate_key cert1.key.pem;
    ssl_session_cache shared:SSL:10m;

    location ~ /.well-known {
      <I've tried lots of combinations here.>
    }


    location / {
        proxy_pass http://localhost:81; # my existing apache instance
        proxy_set_header Host $host;
    }

我也更愿意把它放到 80 块而不是 443 块,但要先小步。

有什么想法吗?

【问题讨论】:

  • /.well-known/acme-challenge 的 ACME 质询请求通过普通 HTTP 在端口 80 上完成,而不是通过端口 443 上的 HTTPS。
  • 这是我关于进入 80 街区而不是 443 街区的最后一点,但我还不能让它在任何一个下工作。
  • 你想实现什么,用 certbot 验证服务器并将 SSL 证书存储在本地?

标签: nginx lets-encrypt


【解决方案1】:

您需要使用root directive 来告知nginx 可以在哪里找到.well-known 目录:

server {
    listen         80;
    server_name    video.maritimeopscorp.com;
    location / {
        return         301 https://$server_name$request_uri;
    }
    location /.well-known {
        root /path/to/enclosing/directory;
    }
}

return 语句包含在默认的location block 中,否则它将始终优先。

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 2018-11-09
    相关资源
    最近更新 更多