Nginx的与我的位置变量失败

问题描述 投票:1回答:1

所以,我想建立一个nginx的default.conf和我在使用变量的麻烦。我想捕捉的子域中$subdomain变量,并用它几次在default.conf

下面是我的配置:

server {
     listen 80;
     server_name  ~^(?<subdomain>.+)\.example\.com$;
     # To allow special characters in headers
     ignore_invalid_headers off;
     # Allow any size file to be uploaded.  
     # Set to a value such as 1000m; to restrict file size to a specific value
     client_max_body_size 0;
     # To disable buffering
     proxy_buffering off;
     location / {
       rewrite ^/$ /$subdomain/index.html break;
       proxy_set_header Host $http_host;
       proxy_pass http://minio-server:9000/$subdomain/;
       #health_check uri=/minio/health/ready;
     }
}

不幸的是在位置块的$subdomain变量的存在失败的nginx完全每次。如果我有$subdomain更换tester的位置块作为一个静态值,则一切正常。

如何正确使用这里的$subdomain变量?

这个问题是一个有些关于这个问题的随访:k8s-ingress-minio-and-a-static-site。在这个问题我试图用入口到反向代理到minio桶,但无济于事。现在,我只是想直接去通过Nginx的,但我的增值经销商不干活。

更新

因此,它似乎proxy_pass将无法正确解析主机如果URL中的变量。

试了两件事情:

  1. 设置解析器像这样:resolver default.cluster.local。我尝试了一堆连击的KUBE-DNS的FQDN,但无济于事,并不断获得minio-server无法找到。
  2. 只是像理查德·史密斯以下提到不使用的变量。相反,改写一切,然后代理通。不过,我不明白这是如何工作,我会非常无用的错误,像这样:10.244.1.1 - - [07/Feb/2019:18:13:53 +0000] "GET / HTTP/1.1" 405 291 "-" "kube-probe/1.10" "-"
nginx nginx-location nginx-reverse-proxy minio
1个回答
1
投票

按照manual page

当变量proxy_pass使用:......在这种情况下,如果该指令指定的URI,它被传递到服务器是,取代了原来的请求URI。

所以,你需要构建完整的URI上游服务器。

例如:

location = / {
    rewrite ^ /index.html last;
}
location / {
    proxy_set_header Host $http_host;
    proxy_pass http://minio-server:9000/$subdomain$request_uri;
}

这可能是更好的使用rewrite...break和使用proxy_pass没有URI。

例如:

location / {
    rewrite ^/$ /$subdomain/index.html break;
    rewrite ^ /$subdomain$uri break;
    proxy_set_header Host $http_host;
    proxy_pass http://minio-server:9000;
}
© www.soinside.com 2019 - 2024. All rights reserved.