【问题标题】:nginx configuration for basic auth that allows lets encrypt to auto renew基本身份验证的 nginx 配置,允许加密自动更新
【发布时间】:2016-07-05 16:23:41
【问题描述】:

目前,我可以通过在我的 nginx 配置中保留以下行来成功安装Let's Encrypt SSL 证书:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

我想在我的网站上启用基本身份验证。以下方法可以很好地做到这一点:

location / {
    try_files $uri $uri/ /index.php?$query_string;
    auth_basic "Restricted Content";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

但是,Let's Encrypt SSL 证书必须每月更新一次。我可以使用 curl 自动执行此更新。但是,Let's Encrypt 沿包含带有前缀的路由的路由回调:

/.well-known/acme-challenge/ 

但是现在,我需要为上面的路由前缀添加一个例外:

location ^~ /.well-known/acme-challenge/ {
    auth_basic off;
}

我已经尝试了上述方法的许多变体,但似乎都没有奏效。我无法使用上述配置安装 Let's Encrypt SSL 证书。我什至确定如果我取消基本身份验证(通过删除以 auth_basic 开头的两行),如果我只有以下内容,则不会安装 Let's Encrypt SSL 证书:

location ^~ /.well-known/acme-challenge/ {
    try_files $uri $uri/ /index.php?$query_string;
}

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

如果有任何建议,我将不胜感激,因此回调路由将在启用基本身份验证时运行。我也有兴趣了解为什么我无法使用上面显示的配置安装 Let's Encrypt,其中甚至没有启用基本身份验证。提前致谢。

其他错误日志:

/var/log/nginx# cat cert.dev.farm-error.log.1
2016/03/18 13:12:26 [error] 12336#12336: *1 open() "/home/forge/cert.dev.farm/public/.well-known/acme-challenge/jGhldzH8cV3d666a44nRy-Gzf98m1u2qUbkWnNv0aMI" failed (2: No such file or directory), client: 66.133.109.36, server: cert.dev.farm, request: "GET /.well-known/acme-challenge/jGhldzH8cV3d666a44nRy-Gzf98m1u2qUbkWnNv0aMI HTTP/1.1", host: "cert.dev.farm"
2016/03/18 13:17:09 [error] 13202#13202: *1 open() "/home/forge/cert.dev.farm/.well-known/acme-challenge/k9jsDB_mkvU5UzvL-B7hd3iA90ZTq61OaDNixoeRQuQ" failed (2: No such file or directory), client: 66.133.109.36, server: cert.dev.farm, request: "GET /.well-known/acme-challenge/k9jsDB_mkvU5UzvL-B7hd3iA90ZTq61OaDNixoeRQuQ HTTP/1.1", host: "cert.dev.farm"
2016/03/18 13:17:09 [error] 13202#13202: *1 FastCGI sent in stderr: "Unable to open primary script: /home/forge/cert.dev.farm/index.php (No such file or directory)" while reading response header from upstream, client: 66.133.109.36, server: cert.dev.farm, request: "GET /.well-known/acme-challenge/k9jsDB_mkvU5UzvL-B7hd3iA90ZTq61OaDNixoeRQuQ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cert.dev.farm"
2016/03/18 13:23:48 [error] 14522#14522: *1 open() "/home/forge/cert.dev.farm/public/.well-known/acme-challenge/5ZBXFn23tOUPcQFNrI3DqUE-l9x3rmdiOkYwabDl-jk" failed (2: No such file or directory), client: 66.133.109.36, server: cert.dev.farm, request: "GET /.well-known/acme-challenge/5ZBXFn23tOUPcQFNrI3DqUE-l9x3rmdiOkYwabDl-jk HTTP/1.1", host: "cert.dev.farm"

【问题讨论】:

  • 你的 nginx 根路径是什么,你在错误日志中看到了吗,它与你传递给letsencrypt的webroot匹配吗?
  • @kyl191 我在上面添加了更多错误日志。让我知道这是否是您正在寻找的东西。根路径是 /home/forge - 我认为问题只是我需要调整以下内容: location ^~ /.well-known/acme-challenge/ { auth_basic off;我想知道以下是否更好?位置 /.well-known/ { auth_basic off;索引 nothing_will_match;自动索引开启; }

标签: ssl nginx configuration basic-authentication lets-encrypt


【解决方案1】:

您可能错过了为/.well-known/acme-challenge 位置块设置的文档根目录。

location ^~ /.well-known/acme-challenge/ {
    root /path/to/your/public/directory;
    try_files $uri;
    auth_basic off;
}

location / {
    ...
}

你说你可以使用 CURL 自动化它,你看过list of available clients吗?

【讨论】:

  • 是的,需要用-w参数将文档根指向原命令中指定的webroot对应。
【解决方案2】:

你可以只使用cli客户端的renew命令:

➜ sudo letsencrypt renew

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/domain.com.conf
-------------------------------------------------------------------------------

The following certs are not due for renewal yet:
  /etc/letsencrypt/live/domain.com/fullchain.pem (skipped)
No renewals were attempted.

【讨论】:

    猜你喜欢
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 2014-04-04
    • 2020-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多