title: Could not find named location "@app" containerised node application
body: <p>I have a containerised nodejs app on my server and I have a nginx webserver so it can use https that is supposed to redirect to the node app but I always get the error in the title and I have no clue why? My node app is showing as restarting though, which might be a problem, but again I don't know why it's restarting as it gives me nothing in the logs:</p>
  
  <p><a href="https://i.stack.imgur.com/xCwBQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xCwBQ.png" alt="enter image description here"></a></p>
  
  <p>My Dockerfile:</p>
  
  <pre><code>FROM node:10-alpine
  
  RUN mkdir -p /home/node/app/node_modules &amp;&amp; chown -R node:node /home/node/app
  
  WORKDIR /home/node/app
  
  COPY package*.json ./
  
  USER node
  
  RUN npm install
  
  COPY --chown=node:node . .
  
  EXPOSE 8080
  
  CMD ["npm", "start"]
  </code></pre>
  
  <p>My docker compose file:</p>
  
  <pre><code>version: '3'
  services:
      app:
          container_name: app
          restart: unless-stopped
          build: 
              context: .
              dockerfile: Dockerfile
          links:
              - db
          networks:
              - app-network
  
      db:
          container_name: db
          image: mongo
          ports:
              - '27017:27017'
  
      webserver:
          image: nginx:mainline-alpine
          container_name: webserver
          restart: unless-stopped
          ports:
              - "80:80"
              - "443:443"
          volumes:
              - web-root:/var/www/html
              - ./nginx-conf:/etc/nginx/conf.d
              - certbot-etc:/etc/letsencrypt
              - certbot-var:/var/lib/letsencrypt
              - dhparam:/etc/ssl/certs
          depends_on:
              - app
          links:
              - app
          networks:
              - app-network
  
      certbot:
          image: certbot/certbot
          container_name: certbot
          volumes:
              - certbot-etc:/etc/letsencrypt
              - certbot-var:/var/lib/letsencrypt
              - web-root:/var/www/html
          depends_on:
              - webserver
          command: certonly --webroot --webroot-path=/var/www/html --email email@gmail.com --agree-tos --no-eff-email --force-renewal -d domain.com  -d www.domain.com 
  
      volumes:
          certbot-etc:
          certbot-var:
          web-root:
              driver: local
              driver_opts:
                  type: none
                  device: /home/root/app/views/
                  o: bind
      dhparam:
          driver: local
          driver_opts:
              type: none
              device: /home/root/app/dhparam/
              o: bind
  
      networks:
          app-network:
              driver: bridge 
  </code></pre>
  
  <p>And my nginx conf file:</p>
  
  <pre><code>server {
      listen 80;
      listen [::]:80;
      server_name domain.com www.domain.com;
  
      location ~ /.well-known/acme-challenge {
        allow all;
        root /var/www/html;
      }
  
      location / {
              rewrite ^ https://$host$request_uri? permanent;
      }
  }
  
  server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      server_name domain.com www.domain.com;
  
      server_tokens off;
  
      ssl_certificate /etc/letsencrypt/live/api.wasdstudios.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/api.wasdstudios.com/privkey.pem;
  
      ssl_buffer_size 8k;
  
      ssl_dhparam /etc/ssl/certs/dhparam-2048.pem;
  
      ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
      ssl_prefer_server_ciphers on;
  
      ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
  
      ssl_ecdh_curve secp384r1;
      ssl_session_tickets off;
  
      ssl_stapling on;
      ssl_stapling_verify on;
      resolver 8.8.8.8;
  
      location / {
          try_files $uri @app;
      }
  
      location @nodejs {
              proxy_pass http://app:8080;
              add_header X-Frame-Options "SAMEORIGIN" always;
              add_header X-XSS-Protection "1; mode=block" always;
              add_header X-Content-Type-Options "nosniff" always;
              add_header Referrer-Policy "no-referrer-when-downgrade" always;
              add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
              # add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
              # enable strict transport security only if you understand the implications
      }
  
      root /var/www/html;
      index index.html index.htm index.nginx-debian.html;
  }
  </code></pre>
  
  <p>First part of my node file:</p>
  
  <pre><code>const express = require('express');
  const app = express();
  const path = require('path');
  const db = require('mongoose');
  
  // Import routes
  const authRoute = require('./routes/auth');
  const recoverRoute = require('./routes/recover');
  const getUser = require('./routes/getUser');
  
  
  // Connect to db
  console.log(process.env.DB_CONNECT);
  db.connect('mongodb://db:27017/app-mongo-database', { useNewUrlParser: true },  (err, client) =&gt; 
  { 
  if(err){ 
      console.log(err); 
  }
  else{
      console.log("connected to db");
  }
  });
  
  // Middleware
  app.use(express.json());
  app.use('/static', express.static(path.join(__dirname, 'static')));
  app.use('/auth/getUser', getUser);
  
  
  // Route middlewares
  app.use('/auth', authRoute);
  app.use('/auth/recover', recoverRoute )
  
  app.listen(8080, () =&gt; console.log('Server started'));
  </code></pre>
  
  <p>This is the log I get when i look into the app's containers log:</p>
  
  <p><a href="https://i.stack.imgur.com/I6k3T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I6k3T.png" alt="enter image description here"></a></p>
  
  <p>And when I go to my domain I get the obvious:</p>
  
  <p><a href="https://i.stack.imgur.com/jDf0x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jDf0x.png" alt="enter image description here"></a></p>
  
  <p>Update:</p>
  
  <p>I do a docker-compose up -b -d command and this is the output ( npm start is running correctly):</p>
  
  <p><a href="https://i.stack.imgur.com/GlSr4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GlSr4.png" alt="enter image description here"></a></p>
  
  <p>It's now displaying this when I do a <code>docker-compose ps</code></p>
  
  <p><a href="https://i.stack.imgur.com/iLduV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iLduV.png" alt="enter image description here"></a></p>
  
  <p>I'ts showing <code>npm start</code> now as it should, but it still does not work with the same error.</p>