Php 为acme挑战在heroku上重写nginx

Php 为acme挑战在heroku上重写nginx,php,nginx,heroku,lets-encrypt,Php,Nginx,Heroku,Lets Encrypt,我正在尝试在heroku上为我的php应用程序设置lets encrypt。 Sabayon提供了一个示例,用于使用Apache从lets encrypt重定向acme质询调用: 我试图将其翻译成Nginx,但无法在Heroku上使用。 在本地,它运行良好 我试过: location ~ ^/.well-known/acme-challenge/(.*)$ { if (!-e $request_filename){ rewrite ^(.*)$ /.well-known/ac

我正在尝试在heroku上为我的php应用程序设置lets encrypt。
Sabayon提供了一个示例,用于使用Apache从lets encrypt重定向acme质询调用:

我试图将其翻译成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是由
中的点引起的。著名的/acme挑战


如何才能做到这一点?

有几件事需要注意:

  • 重定向
  • 使隐藏目录
    。众所周知
    可访问
  • 以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;
}