问题
I am working on setting up our development environment using Vagrant, Docker and NGINX (among other tools).
We have a common microservice architecture and we are using a container per microservice.
As a proof of concept, I am using two test microservices to try to work out the development environment, a and b.
We are running three containers (nginx,a,b) for the purpose of my proof of concept.
Using reverse proxies in NGINX, I want to be able to use the following proxies.
http://localhost:8181/a/ proxies request to the IP address of container 'a'
http://localhost:8181/b/ proxies request to the IP address of container 'b'
To do this, I want to defer the management of each of the services nginx configuration to that service itself. Hopefully, this would allow each of the service to add/remove/modify entries to a /etc/nginx/sites-available volume that is shared with the containers and the host OS.
For example, I would think that I would need the following structure in NGINX
/etc/nginx
- nginx.conf
- sites-available
- a
- b
- sites-enabled
- a (sym link to sites-available/a)
- b (sym link to sites-available/b)
The nginx.conf file looks like the following:
worker_processes 4;
events {
worker_connections 1024;
}
http {
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Assuming that when I pull the IP addresses of the containers for a and b I get the following
a -> 172.17.0.1
b -> 172.17.0.2
and that I have container a exposing port 1234 and container b exposing port 5678, what should the a and b files look like under sites-available?
I tried the following and similar variations, but can't seem to get it to use BOTH /a and /b proxies.
excerpt from /etc/nginx/sites-available/a
server {
listen 80;
location /a/ {
proxy_pass http://172.17.0.1:1234/;
}
}
excerpt from /etc/nginx/sites-available/b
server {
listen 80;
location /b/ {
proxy_pass http://172.17.0.2:5678/;
}
}
For example, using this configuration the following would be the results
http://localhost:8181/a/ proxies to container 'a' just fine
http://localhost:8181/b/ gives a connection refused
来源:https://stackoverflow.com/questions/31386354/how-do-i-setup-nginx-configuration-to-reverse-proxy-to-multiple-containers-using