I'm using consul, consul-template and nginx on docker. When adding each new service, i have to change consul-template source file again. By the way all we're using soap services and proxy. All of them have service uri. How can i write nginx.ctmpl ? example web service end point :
1.1.1.1:123/Service1.asmx
in consul-config, added like this:
"services": [
{
"id": "Svc0",
"name": "Service",
"port": 3307,
"address": "1.1.1.1",
"checks": [
{
"http": "http://1.1.1.1:123/service1.asmx",
"method": "GET",
"interval": "10s",
"timeout": "1s"
}]
}
]
In nginx.ctmpl. I want to change this part for dynamic but i could'nt find any solution because of server part.
upstream backend {
{{ range service "Service" }}
server {{ .Address }}:{{ .Port }};{{ end }}
}
server {
listen 443 ssl;
server_name domainname.com.tr;
proxy_set_header X-Forwarded-Port 443;
ssl_certificate /etc/nginx/tls/..crt;
ssl_certificate_key /etc/nginx/tls/..key;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass https://domainanother;
}
location ^~ /Service1.asmx {
proxy_pass http://backend;
proxy_redirect off;
}
access_log /etc/nginx/log/gw/https/access.log;
error_log /etc/nginx/log/gw/https/error.log;
}
This should do what you want.
Given the following service config:
and the following template:
Consul template will produce the following nginx configuration.