0
votes

I've done this tutorial,

https://reactjs.org/tutorial/tutorial.html

Then uploaded it to production server, running on ubuntu nginx with SSL. Ran npm run build, created the build files and served static files with serve module serve -s -p 8083 build. It runs OK on port 8083.

But when I try to add it as a pm2 service pm2 serve ./build/ 8083 I get a 404 not found (when it's not running the error is 502 Bad Gateway)

I tried several ways, with pm2 serve ./ 8083, pm2 serve ./public/ 8083, etc.

Nginx config:

    location ~* /.(js|jpg|png|css)$ {
     access_log off;
     expires max;
    }
    location = /react-game {
    root /var/www/test.com/html/react-game/build;
    proxy_pass http://localhost:8083;
    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;
    autoindex off;
    }

Any ideas how to replicate serve -s -p 8083 build with pm2?

Thanks!

1

1 Answers

0
votes

I think the main issue is serve is meant to serve static files and pm2 is meant to persistently run a script. Here is an article about serving react with pm2:

https://ygamretuta.xyz/deploy-create-react-app-with-pm2-16beb90ce52

But is there a reason you don't want to just make nginx listen on port 8083 and serve the build files statically by itself? Or is there a reason you're not serving the build files on port 80?