title: Docker Compose NGINX Proxy and Static Files
body: <p>For some reason, my docker-compose/node/nginx stack is having trouble serving static files. The reverse proxy side works but serving my css and javascript fails. For every static file requested, I get an error like this:</p>
  
  <pre><code>customnginx_1 | 2016/03/29 22:42:13 [error] 6#6: *1 open()     
  "/var/www/static/styles/normalize.css" failed (2: No such file or     
  directory), client: 192.168.99.1, server: , request: "GET     
  /styles/normalize.css HTTP/1.1", host: "192.168.99.100", referrer:     
  "http://192.168.99.100/"
  </code></pre>
  
  <p>How do I properly link my "static" directory to my nginx container so these files are served correctly?
  Relevant code:</p>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>db:
    image: postgres:latest
    environment:
      POSTGRES_USER: sizzeDog
      POSTGRES_PASSWORD: awfulPassword
      POSTGRES_DB: ceres
  
  ceres:
    build: .
    links:
      - db
    environment:
      POSTGRES_HOST: db
      POSTGRES_USER: sizzeDog
      POSTGRES_PASSWORD: awfulPassword
      NODE_ENV: production
    volumes:
      - .:/var/www/
  
  customnginx:
    build: nginx/.
    links:
      - ceres
    volumes:
      - static:/var/www/static
    ports:
      - 80:80
  </code></pre>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM node:latest
  
  RUN npm install pm2 -g
  
  VOLUME ["/var/www"]
  ADD start.sh /start.sh
  RUN chmod 755 /start.sh
  
  EXPOSE 5000
  CMD ["/start.sh"]
  </code></pre>
  
  <p>nginx/nginx.conf:</p>
  
  <pre><code>worker_processes 1;
  
  events { worker_connections 1024; }
  
  http {
      sendfile        on;
      keepalive_timeout  65;
  
      gzip              on;
      gzip_http_version 1.0;
      gzip_proxied      any;
      gzip_min_length   500;
      gzip_disable      "MSIE [1-6]\.";
      gzip_types        text/plain text/xml text/css
                        text/comma-separated-values
                        text/javascript
                        application/x-javascript
                        application/atom+xml;
  
      # List of application servers
      upstream app_server {
  
          server ceres:5000;
      }
  
    server {
      listen 80;
  
      root /var/www/static;
  
      location /styles/ {}
      location /dist/ {}
  
      location / {
          proxy_redirect off;
          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_set_header   Host                   $http_host;
          proxy_set_header   X-NginX-Proxy    true;
          proxy_set_header   Connection "";
          proxy_http_version 1.1;
          proxy_pass         http://app_server;
      }
    }
  }
  </code></pre>
  
  <p>nginx/Dockerfile:</p>
  
  <pre><code>FROM nginx:alpine
  
  VOLUME ["/var/www/static"]
  
  RUN rm -v /etc/nginx/nginx.conf
  
  ADD nginx.conf /etc/nginx/
  
  CMD ["nginx", "-g", "daemon off;"]
  </code></pre>
  
  <p>UPDATE: Adding <code>include /etc/nginx/mime.types;</code> to the http block of the <code>nginx.conf</code> fixed the empty css issue :).</p>