Nginx子域:重定向/.well-已知路径以进行加密

时间:2016-08-11 14:05:08

标签: redirect meteor nginx subdomain lets-encrypt

我有一个运行两个子域的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-Subdomain不在/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;
    }
}    

2 个答案:

答案 0 :(得分:2)

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

您需要删除它们。

请参阅location指令中的this document

答案 1 :(得分:2)

好的,感谢理查德史密斯的提示我解决了它:

我将此保留在domain.com-Part的Config-Part中,如this教程中所述。

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

但是将其放入subdomain.domain.com的Config-Part中:

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

它的作用是将subdomain.domain.com/.well-known/[anything]的任何请求作为domain.com/.well-known/[anything]处理,因此letsencrypt-auto没有错误。