title: 502 bad gateway error when deploying to nginx web server
body: <p>I built a react app using the <code>create-react-app</code> and <code>npm run build</code>commands and connected it to node with <code>server.js</code>file in the directory created by <code>create-react-app</code>.</p>
  
  <p>When running the command <code>node server</code> locally it works perfectly fine however when I pushed the changes to my nginx server I started to get a 502 bad gateway status. Why is this happening? Node is running when I get this error. </p>
  
  <p>Here is the <code>server.js</code> code </p>
  
  <pre><code>onst express = require('express');
  const path = require('path');
  
  const app = express();
  
  
  app.use('/js', express.static(path.join(__dirname, 'src/')));
  app.use('/css', express.static(path.join(__dirname, 'src/')));
  
  app.use(express.static(path.join(__dirname , '/public/build')));
  
  
  // Handles any requests that don't match the ones above
  app.get('/', (req,res) =&gt;{
      res.sendFile(path.join(__dirname , "/public/build/index.html"));
  
  });
  
  const port = process.env.PORT || 5000;
  app.listen(port);
  
  console.log('App is listening on port ' + port);
  </code></pre>
  
  <p>the error log </p>
  
  <pre><code>[error] 7422#7422: *4477 connect() failed (111: Connection refused) while connecting to upstream, client: 162.84.158.175, server: anthonyjimenez.me, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:3000/", host: "anthonyjimenez.me"
  </code></pre>
  
  <p>and the config file </p>
  
  <pre><code>http {
  
      ##
      # Basic Settings
      ##
  
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      # server_tokens off;
  
      # server_names_hash_bucket_size 64;
      # server_name_in_redirect off;
  
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
  
      ##
      # SSL Settings
      ##
  
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
      ssl_prefer_server_ciphers on;
  
      ##
      # Logging Settings
      ##
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  
      ##
      # Gzip Settings
      ##
  
      gzip on;
  
      # gzip_vary on;
      # gzip_proxied any;
      # gzip_comp_level 6;
      # gzip_buffers 16 8k;
      # gzip_http_version 1.1;
      # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  
      ##
      # Virtual Host Configs
      ##
  
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
  }
  
  </code></pre>