title: error 503 when using nginx-proxy container like a front-end server to access multiple container on the same host
body: <p>Solution found at : <a href="https://serverfault.com/questions/880212/error-503-when-using-nginx-proxy-container-like-a-front-end-server-to-access-mul">https://serverfault.com/questions/880212/error-503-when-using-nginx-proxy-container-like-a-front-end-server-to-access-mul</a></p>
  
  <p>I want to be able to have access to multiple containers, on the same host, containing web applications.</p>
  
  <p>When I want to access to the host (by his ip address) or to the containers (e.g. by host_ip_adress/container1), I get for both a 503 error from Nginx. What I want is to access my container1 by ip_addrress_host/container1.</p>
  
  <p>The solution I found on internet was to set an nginx-proxy front-end server (source: <a href="https://blog.florianlopes.io/host-multiple-websites-on-single-host-docker/" rel="nofollow noreferrer">https://blog.florianlopes.io/host-multiple-websites-on-single-host-docker/</a>)</p>
  
  <p><strong>My docker-compose file :</strong></p>
  
  <pre><code>version: '2'
  services:
    nginx-proxy:
      image: jwilder/nginx-proxy
      ports:
        - "80:80"
      volumes:
        - /var/run/docker.sock:/tmp/docker.sock
    site_a:
     image: php:7.0-apache
     expose:
     - "80"
     environment:
     - VIRTUAL_HOST=192.168.12.28/container1
     - VIRTUAL_PORT=80
     volumes:
     - ./php:/var/www/html
   site_b:
     image: php:7.0-apache
     expose:
     - "80"
     environment:
     - VIRTUAL_HOST=192.168.12.28/container2
     - VIRTUAL_PORT=80
     volumes:
     - ./php:/var/www/html
  </code></pre>
  
  <p><strong>I run it with the command :</strong> </p>
  
  <pre><code>docker-compose up
  </code></pre>
  
  <p>My entries in <strong>the /etc/hosts file</strong> : </p>
  
  <pre><code>127.0.1.1       container1
  127.0.0.1       container2
  </code></pre>
  
  <p><strong>The logs I see when I make a request from the outside :</strong></p>
  
  <pre><code>nginx-proxy_1  | nginx.1    | 192.168.12.28 192.168.12.82 - - [25/Oct/2017:09:46:42 +0000] "GET /container1 HTTP/1.1" 503 615 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
  nginx-proxy_1  | nginx.1    | 192.168.12.28 192.168.12.82 - - [25/Oct/2017:09:46:42 +0000] "GET /favicon.ico HTTP/1.1" 503 615 "http://192.168.12.28/container1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
  </code></pre>
  
  <p>Thank you for your help, and sorry for my bad english! :-)</p>
  
  <p><strong>Edit</strong> : 
  I have tried to put nginx-proxy containers and my web application containers in the same "docker network" as explain in docker hub (<a href="https://hub.docker.com/r/jwilder/nginx-proxy/" rel="nofollow noreferrer">https://hub.docker.com/r/jwilder/nginx-proxy/</a>) but when I do :</p>
  
  <pre><code>docker-compose up
  </code></pre>
  
  <p>I have an error: </p>
  
  <pre><code>ERROR: Service "site_b" uses an undefined network "proxy-nginx"
  </code></pre>
  
  <p><strong>Edit 2 :</strong></p>
  
  <p><strong>Here are my logs for the nginx-proxy container at the start :</strong> </p>
  
  <pre><code>forego     | starting dockergen.1 on port 5000
  forego     | starting nginx.1 on port 5100
  dockergen.1 | 2017/10/25 14:01:53 Generated '/etc/nginx/conf.d/default.conf' from 3 containers
  dockergen.1 | 2017/10/25 14:01:53 Running 'nginx -s reload'
  nginx.1    | 2017/10/25 14:01:54 [warn] 30#30: server name "192.168.12.28/container1" has suspicious symbols in /etc/nginx/conf.d/default.conf:60
  nginx.1    | 2017/10/25 14:01:54 [warn] 30#30: server name "192.168.12.28/container2" has suspicious symbols in /etc/nginx/conf.d/default.conf:74
  dockergen.1 | 2017/10/25 14:01:54 Watching docker events
  dockergen.1 | 2017/10/25 14:01:54 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
  </code></pre>
  
  <p><strong>Edit 3 :</strong></p>
  
  <p>So, now, my nginx config look like : </p>
  
  <pre><code>server {
     listen  192.168.12.28;
     server_name 192.168.12.28;
  
     access_log  /var/log/nginx/host.access.log;
  
     location / {
         proxy_http_version 1.1;
         proxy_pass http://172.23.0.3:80;
         proxy_set_header Host $host;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_buffering Off;
         proxy_cache_bypass $http_upgrade;
     }
  
     location /container1/ {
         proxy_http_version 1.1;
         proxy_pass http://172.23.0.3:80;
         proxy_set_header Host $host;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_buffering Off;
         proxy_cache_bypass $http_upgrade;
     }
  
     location /container2/ {
         proxy_http_version 1.1;
         proxy_pass http://172.23.0.2:80;
         proxy_set_header Host $host;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_buffering Off;
         proxy_cache_bypass $http_upgrade;
     }
  }
  </code></pre>
  
  <p>When I go to <a href="http://192.168.12.28/container1" rel="nofollow noreferrer">http://192.168.12.28/container1</a></p>
  
  <p>my log is : </p>
  
  <pre><code>site_a_1  | 172.23.0.1 - - [26/Oct/2017:09:22:40 +0000] "GET /container1/ HTTP/1.1" 404 449 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
  </code></pre>
  
  <p>and when I go to <a href="http://192.168.12.28/container2" rel="nofollow noreferrer">http://192.168.12.28/container2</a></p>
  
  <p>my log is : </p>
  
  <pre><code>site_b_1  | 172.23.0.1 - - [26/Oct/2017:09:22:50 +0000] "GET /container2/ HTTP/1.1" 404 449 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
  </code></pre>
  
  <p>And for both , the response is 404 not found. It seems that it looks into the server of my containers the "/container1" or "/container2" path? If it's true, can I force him to look after /var/www/html/ ?</p>