【问题标题】:Nginx Subdomains: Redirect /.well-known path for Let's EncryptNginx 子域:重定向 /.well-known path for Let's Encrypt
【发布时间】:2016-12-18 07:50:06
【问题描述】:

我有一个运行有两个子域的 Nginx 服务器。其中一个使用 proxy_pass 将所有内容重定向到 Meteor 应用程序,另一个子域仅使用 Laravel,但位于与普通域不同的目录中。

所以,当我启动 ./letsencrypt-auto 时,我收到以下两个子域的错误消息:

Failed authorization procedure. subdomain.mydomain.com (http-01): urn:acme:error:unauthorized ::
The client lacks sufficient authorization :: Invalid response from http://subdomain.mydomain.com/.well-known/acme-challenge/xyzxyzxy_xzyzxyxyyx_xyzyxzyxz: "<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>

我对此的解释是,它不起作用,因为我的 Laravel 子域不在 /var/www/domain.com/html 中,而是在 /var/www/laravel/html 中,而我的 Meteor-Application 在其他地方,而 ngnix 只是代理传递。

所以我的问题是:我可以将两个子域的 /.well-known/acme-challenge 重定向到真正的 /.well-known 以便让letsencrypt-auto 不会抛出这个错误吗?


更多信息:

我试过了

location '/.well-known/acme-challenge' {
    default_type "text/plain";
    root /tmp/letsencrypt-auto;
}

但它没有工作......

为我的 Meteor 子域配置:

server {
        listen 80;
        listen [::]:80;

        # SSL configuration
        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;

        […] SSL stuff […]


        server_name meteor.domain.com;

        location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header X-Forwarded-For $remote_addr;
        }

        location ~ /.well-known {
                allow all;
        }

}

为我的 Laravel 子域配置:

server {
        listen 80;
        server_name laravel.domain.com;

        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;

        […] SSL stuff […]

        root /var/www/laravel/html;


        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

    location ~ /.well-known {
                allow all;
        }

    location ~ \.(hh|php)$ {
        fastcgi_keep_conn on;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}    

【问题讨论】:

    标签: redirect meteor nginx subdomain lets-encrypt


    【解决方案1】:

    好的,感谢 Richard Smith 的提示,我解决了这个问题:

    我将它保存在 domain.com-Part 的配置部分中,如this 教程中所述。

    location / {
        try_files $uri $uri/ =404;
    }
    

    但将其放入 subdomain.domain.com 的配置部分中:

    location /.well-known/ {
        root /var/www/domain.com/html;
    }
    

    它所做的是将任何对subdomain.domain.com/.well-known/[anything] 的请求作为domain.com/.well-known/[anything] 处理,因此letsencrypt-auto 不会出错。

    【讨论】:

      【解决方案2】:

      您的 location ~ /.well-known 块是正则表达式位置,优先于您尝试添加的前缀位置。

      您需要删除它们。

      参见 location 指令中的 this document

      【讨论】:

        猜你喜欢
        • 2020-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-10
        • 2018-01-11
        • 2018-11-09
        • 2017-11-20
        相关资源
        最近更新 更多