title: PM2, 502 Bad gateway, Nginx serving both React app and NodeJS API
body: <p>I'm serving both React app and NodeJS API with Nginx configuration (from Nginx <code>sites-available</code> folder):</p>
  <pre><code>server {
      listen 80;
      listen [::]:80;
  
      root /var/www/html;
  
      index index.html index.htm index.nginx-debian.html;
  
      server_name my-site-name.com www.my-site-name.com;
  
      location /api/ {
          proxy_pass http://localhost:3000;
  
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
  
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
      }
  
      location / {
          root /var/www/html/;
          try_files $uri /index.html;
      }
  }
  </code></pre>
  <p>If I start the NodeJS API on the server with <code>npm start</code>- everything works. If I run the API as a process with PM2 - I get 502 Bad gateway by calling any API endpoint.</p>
  <p>EDIT: PM2 doesn't serve app at expected port (3000). Found out by turning it off.</p>