title: How to serve couple containers with domain names with Docker NGINX image
body: <p>I need to host multiple sites with my docker-machine in future, but know i'm trying to launch it on localhost.</p>
  
  <p>The main purpose is to get certain site, of course I need to start with my <code>/etc/hosts</code> file on OS X, below is listing:</p>
  
  <pre><code>127.0.0.1   localhost
  255.255.255.255 broadcasthost
  
  127.0.0.1     dev.proling.ru
  127.0.0.1     dev.vshvetsov.ru
  </code></pre>
  
  <p>This configuration provide for me access to sites with chosen domains independently of DNS settings. Now I'll show my <code>docker-compose.yml</code>:</p>
  
  <pre><code>version: '2'
  
  services:
    mysql:
      build: mysql/
      restart: always
      volumes:
        - mysql_data:/var/lib/mysql
      container_name: mysql
    vshvetsov:
      depends_on:
        - mysql
      build: vshvetsov/
      ports:
        - 8000:80
      restart: always
      container_name: vshvetsov
    proling:
      depends_on:
        - mysql
      build: proling/
      ports:
        - 8003:80
      restart: always
      container_name: proling
    nginx:
      depends_on:
        - proling
        - vshvetsov
      image: nginx
      restart: always
      ports:
       - "80:80"
      volumes:
       - ./nginx/volume:/etc/nginx
      container_name: nginx
  volumes:
      mysql_data:
  </code></pre>
  
  <p>Both site containers works perfectly on <code>localhost:8000</code> and <code>localhost:8003</code> and below is my <code>nginx/volume</code> folder tree:</p>
  
  <pre><code>volume
      ├── conf.d
      │   ├── default.conf
      │   ├── proling.ru
      │   └── vshvetsov.ru
      ├── fastcgi_params
      ├── koi-utf
      ├── koi-win
      ├── mime.types
      ├── modules -&gt; /usr/lib/nginx/modules
      ├── nginx.conf
      ├── scgi_params
      ├── uwsgi_params
      └── win-utf
  </code></pre>
  
  <p>So the only way to impact on my NGINX configuration is to put <code>.conf</code> files in <code>conf.d</code> directory and below are both of them:</p>
  
  <p>dev.proling.ru</p>
  
  <pre><code>server {
      listen  80;
      server_name  www.proling.ru;
      rewrite ^ http://proling.ru$request_uri? permanent; #301 redirect
  }
  
  server {
      listen 80;
  
      server_name proling.ru *.proling.ru;
  
          location / {
  
              proxy_pass http://proling;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection 'upgrade';
              proxy_set_header Host $host;
              proxy_cache_bypass $http_upgrade;
  
              access_log /var/log/nginx/proling.ru-access.log;
          }
  }
  </code></pre>
  
  <p>And dev.vshvetsov.ru</p>
  
  <pre><code>server {
      listen 80;
  
      server_name www.vshvetsov.ru vshvetsov.ru dev.vshvetsov.ru;
  
      location / {
          proxy_pass http://vshvetsov;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
          access_log /var/log/nginx/vshvetsov.ru-access.log;
      }
  }
  </code></pre>