Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

834
Views
Nginx docker compose - volume add nginx.conf (reverse proxy)

I want to containerize my web applications. Currently, I am using Apache to provide a couple of PHP apps.

Every app should be provided by their own container. Nginx should be reachable by port 80/443. Depending on the sub route it should proxying to one of the containers.

For example:

www.url.de/hello1 --> hello1:80
www.url.de/hello2 --> hello2:80

docker-compose.yml:

version: '3'
services:
    nginx:
            image: nginx:latest
            container_name: reverse_proxy
            volumes:
                    - ./nginx.conf:/etc/nginx/nginx.conf
            ports:
                    - "80:80"
                    - "443:443"
            networks:
                    - app-network
            depends_on:
                    - hello1
                    - hello2

    hello1:
            build: ./test1
            image: hello1
            container_name: hello1
            expose:
                    - "80"
            networks:
                    - app-network
    hello2:
            build: ./test2
            image: hello2
            container_name: hello2
            expose:
                    - "80"
            networks:
                    - app-network

networks:
    app-network:

nginx.conf:

events {

}

http {
    error_log /etc/nginx/error_log.log warn;
    client_max_body_size 20m;

    proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;


    server {
            server_name wudio.de;

            location / {
                    proxy_pass http://hello1:80;
            }

            location /hello1/ {
                    proxy_pass http://hello1:80;
                    rewrite ^/hello1(.*)$ $1 break;
            }

            location /hello2/ {
                    proxy_pass http://hello2:80;
                    rewrite ^/hello2(.*)$ $1 break;
            }

    }
}

If I run docker-compose up -d, only the container with image webapp-test1 is online. And I also can reach it by curl localhost:8081. Nginx is not running. If I remove the line in which I add nginx.conf to the volume of Nginx, it´s working. What I´m doing wrong?

Edit1:

http:// was missing. But proxying still not working on subroutes. Only location / is working. How I get /hell1 running?
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Note the proxy_pass statement. You have to mention the protocol in that statement. Also note how you can refer to the name of the service in your docker-compose.yml file (in this case hello1).

events {

}

http {
    error_log /etc/nginx/error_log.log warn;
    client_max_body_size 20m;

    proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;

    server {
       listen 80;
       location / {
          try_files $uri @proxy ;
       }

       location @proxy {
          proxy_pass http://hello1:80/;
       }
    }
}

Edit: Try this instead

events {

}

http {
    error_log /etc/nginx/error_log.log warn;
    client_max_body_size 20m;

    proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;

    server {
      listen 80;
      location / {
          try_files $uri @proxy ;
      }

      location @proxy {
          if ($request_uri ~* "^\/hello1(\/.*)$") {
            set $url "http://hello1:80$1";
          }

          if ($request_uri ~* "^\/hello2(\/.*)$") {
            set $url "http://hello2:80$1";
          }

          proxy_pass "$url"
      }
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!