2

I'm trying to create an nginx reverse proxy for docker containers and for some reason when I try to insert the variable containing the service's hostname and try to access https://localhost/services/my-service/landing-page I get

Cannot GET /

This works

server {

  resolver 127.0.0.11 valid=300s;
  resolver_timeout 60s;

  listen 443 default_server ssl;
  server_name localhost;

  ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
  ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

  location /services/my-service/ {
    set $service_url my-service;
    proxy_pass http://my-service/;
    proxy_set_header Host $host;
    proxy_redirect http:// https://;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

But this does not

server {

  resolver 127.0.0.11 valid=300s;
  resolver_timeout 60s;

  listen 443 default_server ssl;
  server_name localhost;

  ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
  ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

  location /services/my-service/ {
    set $service_url my-service;
    proxy_pass http://$service_url/;
    proxy_set_header Host $host;
    proxy_redirect http:// https://;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}
TheAschr
  • 899
  • 2
  • 6
  • 19
  • Does this answer your question? [Dynamic proxy\_pass to $var with nginx 1.0](https://stackoverflow.com/questions/5743609/dynamic-proxy-pass-to-var-with-nginx-1-0) – Nick Roz Sep 28 '22 at 16:32

0 Answers0