1

I am having the following configuration:

I have 5 LXC containers that are running nginx. On each container there are a couple of virtual hosts set up in nginx. That means for a container I have multiple virtual hosts that are available through port 80.

Each container has an IP like 10.0.3.100, 10.0.3.101, etc.

On the host machine, I also have a nginx server running that has virtual hosts defined.

I would like to know how can I achieve the following: The nginx virtual hosts on the host machine to map on each virtual host on the containers.

For example: HOST: d1.example.com -> CONTAINER1: d1.example.com HOST: d2.example.com -> CONTAINER1: d2.example.com HOST: d3.example.com -> CONTAINER2: d3.example.com

All of them should be available on port 80.

Is there any way to achieve this setup?

0

This is a reverse-proxy and the directive you are looking for is proxy_pass. The host instance of nginx will have multiple server containers like:

server {
  listen 80;
  server_name d1.example.com;
  location / {
    proxy_pass       http://10.0.3.100;
    proxy_set_header Host              $host;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Accept-Encoding   "";
  }
}

See the proxy module documentation and the WebSocket documentation (if applicable).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.