1

I have a docker container that just shows random pictures of cats being random. The image for the container resides on the server I use for my personal site, and I would like to add a route in Nginx that allows me to navigate to the app and see the cat of the day.

Using the following configuration, I get 404'd when I attempt to navigate to my_site.com/cats.

sites-available/my_site.conf:

server {
  listen 443 ssl;
  include snippets/my_site-ssl.conf;
  include snippets/ssl-params.conf;

  server_name my_site.com www.my_site.com;
  root /var/www/my_site.com/html;

  #working location directives for my_site here...

  location = /cats {
    proxy_pass https://localhost:5001;
  }
}

The docker container is invoked with:

$ docker run --rm -d -p 5001:5000 --name cats handsomegorilla/cats

Every permutation of search I've performed for solving this problem just returns results for some variation of 'how to run nginx in a container', which is decidedly not my objective here.

I'm new to using Docker, so it's possible that this is something I should be asking Stack Overflow, but I thought I would begin with the server and work my way back to Docker.

1 Answers1

0

Right, so I solved this by doing the following:

I made /etc/nginx/conf.d/my_site.conf:

upstream catApp {
  server 127.0.0.1:5001;
}

I modified the location directive in sites-available/my_site.com to use

# unchanged configuration stuff...

 location = /cats {
   proxy_pass http://catApp/; #trailing / is important for removing req uri
 }
}

The reloaded nginx and started the app with

$ docker run --rm -d -p 127.0.0.1:5001:5000 handsomegorilla/cats