1

I'm trying to access multiple docker containers running on a server via a nginx as a reverse proxy.

Each container is a self contained CMS. Some are wordpress, some are drupal, etc etc.

The command I'm starting the containers with:

docker run -p 0.0.0.0:{$port}:80 -i -t loader-docker 

The big difference here is I want to access each container via a path rather than a subdomain.

For example: http://example.com/docker-1 http://example.com/docker-2

I can do this easily enough with the following config

server { listen 80; server_name example.com; location / {} location /docker-1/ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass docker.server:8001; } location /docker-2/ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass docker.server:8002; } } 

When I go to http://example.com/docker-1 I'm hitting the docker container running on port 8001 on an internal server. Likewise when I go to http://example.com/docker-2

The issue is as each of these containers are running CMS's none of the paths are now correct and all resources fail to load.

The path the CMS is looking for is actually docker.server (the internal server) but it's getting http://example.com/

Is it possible to solve this in nginx, or do I have to write custom .htaccess rules for each of the containers? If so how would I go about that?

I should note that each container is running Apache as its web server.

1 Answer 1

-1

That is common issue for who want to work on sandbox envoriment. If i got your problem correctly, you are looking for wrong part of the system for solution.

You need to change your cms paths. I think you can use environment variables maybe called root_path and then we can pass proxy value or something else at initial time to the container.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.