-
How-To Question: Need to write a proxy_pass statement but the upstream name is dynamically created in nginx-proxy docker version. Background: I need to integrate specific location ~ ^/myresources/ {
add_header Cache-Control "public, max-age=2419200, must-revalidate";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri @backend-via-proxy;
}
location @backend-via-proxy {
proxy_pass http://my-backend;
proxy_buffering on;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
The challenge is that with the containerized # test.example.com/
upstream test.example.com-0123456789abcdef {
# Container: test-example-com-web-1
# networks:
# nginx-proxy (reachable)
# test-example-com_internal_network (unreachable)
# IP address: 172.18.0.6
# exposed ports: 6000/tcp 8000/tcp
# default port: 80
# using port: 6000
server 172.18.0.6:6000;
} Since the alphanumeric portion of the upstream name is dynamically created, how do I create a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
By the way, the reason I have to pass to the backend is that these resources are inside the container, not mounted on a volume that could be attached to |
Beta Was this translation helpful? Give feedback.
-
The upstream name is not random. It is a sha1-hash of the But normally nginx-proxy does the complex stuff for you. |
Beta Was this translation helpful? Give feedback.
-
Thanks. I didn't take the time to see if that was the same hash algorithm.... I have more than one upstream for this server, so I do need to know the name of the upstream and now that I know the generated value is stable and predictable, I can use it. Thanks, I'll try this today but I am sure this is the answer. |
Beta Was this translation helpful? Give feedback.
The upstream name is not random. It is a sha1-hash of the
VIRTUAL_PATH
. So once you calculate it, you can re-use it.In the Per-VIRTUAL_PATH location configuration there is a shell command to get the hash of the URL.
Or you could copy it from the generated config.
But normally nginx-proxy does the complex stuff for you.
See: Per-VIRTUAL_HOST location configuration and Per-VIRTUAL_PATH location configuration
If you create the _location file nginx-proxy will include it and you do not have to reference it.