With jwilder nginx-proxy, how to proxypass a subdirectory url to a specific container?

I use jwilder/nginxproxy to make a reverse proxy. I try to redirect http://localhost:8000/api to a specific php service.

The directory structure:

  • JCoCo Code Coverage inside Docker Image
  • Submitting a jar to sequenceiq docker-spark container
  • Start only one service in a docker-compose.yml with ansible docker_service module
  • Deimos Expecting 'MESOS_SLAVE_PID' in environment variables
  • Build docker image with jetty - when should I build?
  • Can docker containers be used for live migration of a group of running applications?
  • .
    +-- docker-compose.yml
    +-- nginx
    +-- nodejs
    |   +-- index.js
    |   +-- …
    +-- php
    |   +-- api


    version: "3.1"
        image: jwilder/nginx-proxy:alpine
          - "8000:80"
          - ./php:/srv/www
          - /var/run/docker.sock:/tmp/docker.sock:ro
        image: node:alpine
          - NODE_ENV=production
          - VIRTUAL_HOST=localhost
          - VIRTUAL_PORT=8080
          - "8080"
        working_dir: /home/app
        restart: always
          - ./nodejs:/home/app
        command: ["node", "index.js"]
        image: php:apache
          - VIRTUAL_HOST=localhost
          - ./php:/var/www/html

    This works fine for the nodejs service.

    Now, I would like to redirect calls to http://localhost:8000/api to the php service. I imagine that I have to add to the nginx conf something like:

    server {
      location /api {
        proxy_pass http://php:80/api;
        proxy_set_header Host $host;

    This feature is not built into the lib.
    So, how can I achieve that?

  • passing docker flag --net=host to selenium/standalone-chrome-debug, image fails
  • bluemix docker-compose String indices must be integers
  • Docker build dockerfile
  • how to make fail2ban read json docker logs
  • How to build sidekiq and rails image with docker?
  • Is there any way to install Docker Tooling Kit in mars on Windows
  • One Solution collect form web for “With jwilder nginx-proxy, how to proxypass a subdirectory url to a specific container?”

    One approach is to give the php app its own virtual host:

        image: php:apache
          - VIRTUAL_HOST=api.localhost
          - ./php:/var/www/html

    Then, it will be accesible as this:

    curl -H 'Host: api.localhost' http://localhost:8000/api

    Setting the header can be achieved in practically any language. Or to avoid setting custom header, you can add that DNS to your /etc/hosts file: api.localhost

    So you can curl as this:

    curl -H http://api.localhost:8000/api

    This is how set custom headers, for example in node:

    var request = require('request')
    var formData = {}
        headers: {
          'Host': 'api.localhost'
        uri: 'http://localhost:8080',
        method: 'POST'
      }, function (err, res, body) {
          console.log("it works")

    But, I recommend you to go for the /etc/hosts approach, that should has an equivalent in production environment (a DNS server). So you don’t need to touch node code.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.