所以,我想建立一个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中的变量。
试了两件事情:
resolver default.cluster.local
。我尝试了一堆连击的KUBE-DNS的FQDN,但无济于事,并不断获得minio-server
无法找到。10.244.1.1 - - [07/Feb/2019:18:13:53 +0000] "GET / HTTP/1.1" 405 291 "-" "kube-probe/1.10" "-"
按照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;
}