I am having some problems to configure a nginx reverse proxy with some url. My configuration is:
events {
worker_connections 768;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
access_log /dev/stdout combined;
error_log /dev/stdout warn;
server {
ssl_certificate /opt/ssl/ca.crt;
ssl_certificate_key /opt/ssl/ca.key;
listen 443 ssl;
location /api/v1/namespaces/mynamespace/services/prometheuslb/proxy/ {
resolver 127.0.0.1 valid=30s;
set $endpoint "http://prometheuslb.mynamespace.svc.skydns.local:9090/";
proxy_pass $endpoint;
}
location /api/v1/namespaces/mynamespace/services/pushgatewaylb/proxy/ {
resolver 127.0.0.1 valid=30s;
set $endpoint "http://pushgatewaylb.mynamespace.svc.skydns.local:9091/";
proxy_pass $endpoint;
}
location /api/v1/namespaces/mynamespace/services/cratedb/proxy/ {
resolver 127.0.0.1 valid=30s;
set $endpoint "http://cratedb.mynamespace.svc.skydns.local:4200/";
proxy_pass $endpoint;
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
}
}
}
For the Prometheus url I have an infinite loop so the page doesnt load.
For Pushgateway it redirects wrong, becuase it should look for styles in /api/v1/namespaces/mynamespace/services/pushgatewaylb/proxy/ but it dismisses that url part, for example it should look for styles in /api/v1/namespaces/mynamespace/services/pushgatewaylb/proxy/static/jquery-2.1.4.min.js
And for cratedb I receive this error: Resource interpreted as Stylesheet but transferred with MIME type text/html
I can modify the existing server block, but I cannot create a separate server block.
I tested pinging targets and they work ok, also if I dont use varibles they work ok, but I need to use variables with resolver becuase we need nginx start ok even though endpoints are not available.
How can I fix these errors? Thank you.
Edit1:
Thank you very much @Richard Smith for the response, I am not expert in nginx and help is very appreciated: The new config:
location ~ ^/api/v1/namespaces/mynamespace/services/prometheuslb/proxy(/.*)$ {
resolver 127.0.0.1 valid=30s;
set $endpoint "http://prometheuslb.mynamespace.svc.skydns.local:9090";
proxy_pass $endpoint$1;
}
location ~ ^/api/v1/namespaces/mynamespace/services/pushgatewaylb/proxy(/.*)$ {
resolver 127.0.0.1 valid=30s;
set $endpoint "http://pushgatewaylb.mynamespace.svc.skydns.local:9091";
proxy_pass $endpoint$1;
}
location ~ ^/api/v1/namespaces/mynamespace/services/cratedb/proxy(/.*)$ {
resolver 127.0.0.1 valid=30s;
set $endpoint "http://cratedb.mynamespace.svc.skydns.local:4200";
proxy_pass $endpoint$1;
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
}
fixed the cratedb style error and Prometheus infinite loop.
Now I have other errors in prometheus in inspect of browser says GET https://domain/api/v1/namespaces/clautagsfed/services/prometheuslb/proxy/api/v1/query?query=time()&_=1541522597396 400 (Bad Request) ,
so seems there is something missing in config yet (without variables it works ok).
And regarding Pushgateway the same problem as explained above that it should look style in /api/v1/namespaces/mynamespace/services/pushgatewaylb/proxy/static/jquery-2.1.4.min.js but it looks in jquery-2.1.4.min.js
Thanks