【问题标题】:nginx rewrite on heroku for acme-challengenginx 在 heroku 上重写以进行 acme-challenge
【发布时间】:2017-07-26 00:38:18
【问题描述】:

我正在尝试使用https://github.com/dmathieu/sabayon 在heroku 上为我的php 应用程序设置lets-encrypt。
Sabayon 提供了一个使用 Apache 从lets-encrypt 重定向acme-challenge 调用的示例:https://github.com/dmathieu/sabayon#php-apps

我试图将它翻译成 Nginx,但我无法让它在 Heroku 上工作。
在本地运行良好。

我试过了:

location ~ ^/.well-known/acme-challenge/(.*)$ {
    if (!-e $request_filename){
      rewrite ^(.*)$ /.well-known/acme-challenge/index.php?q=$1 last;
      break;
    }
}

location ~ \.php$ {
    try_files @heroku-fcgi @heroku-fcgi;
}

但这会导致 PHP 代码作为下载的文件。

我也试过了:

location /.well-known/acme-challenge/ {
    # try to serve file directly, fallback to rewrite
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /.well-known/acme-challenge/index.php/$1 last;
} 

location ~ \.php$ {
    try_files @heroku-fcgi @heroku-fcgi;
}

这会导致 403。

更新 我刚刚发现 403 是由.well-known/acme-challenge 中的点引起的。

如何才能做到正确?

【问题讨论】:

    标签: php nginx heroku lets-encrypt


    【解决方案1】:

    有几件事需要注意:

    • 重定向
    • 使隐藏目录.well-known可访问
    • 将php文件作为php执行

    所以这最终对我有用:

    location ^~ /.well-known/acme-challenge/ {
        allow all;
        # try to serve file directly, fallback to rewrite
        try_files $uri @rewriteacme;
    }
    
    location @rewriteacme {
        rewrite ^(.*)$ /.well-known/acme-challenge/index.php/$1 last;
    }
    
    location ^~ /.well-known/acme-challenge/index.php {
        try_files @heroku-fcgi @heroku-fcgi;
        internal;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-11-09
      • 2017-06-07
      • 2018-02-25
      • 1970-01-01
      • 2017-10-04
      • 1970-01-01
      • 2016-04-18
      • 2016-11-17
      • 2019-04-05
      相关资源
      最近更新 更多