Deploy Frontity on NGINX Server

Hi, i saw the guide on how to deply on Now, but what should i do if i have to deploy on port 3001 on NGINX in a VPS?

Thanks

Frontity is a regular Node app, so you can follow any guide written for Node, like this one:

If you just start the server using npm run serve, it won’t restart if it crashes, or when the server reboots. For that reason, we recommend you to use either forever or pm2.

The alternative to npm run serve when using a node file is:

node node_modules/frontity/dist/commands.js serve --port 3001

Forever

So you can start forever using:

forever start node_modules/frontity/dist/commands.js serve --port 3001

pm2 (alternative)

With pm2 that is:

pm2 start node_modules/frontity/dist/commands.js -- serve --port 3001

or using npm to run a npm script:

pm2 start npm --name "frontity" -- run serve -- --port 3001

You can test both forever or pm2 in your machine first.

Nginx

For Nginx, nothing fancy either. Any copy-paste configuration of a Node configuration for Nginx should work fine:

server {
    listen 80;
    server_name yoursitename.com;

    location / {
        root /home/nodeuser/app   
        proxy_pass http://127.0.0.1:3001;
        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;
    }
}

EDIT: Sorry, I forgot to add port 3001

5 Likes

Thank you for your help.

My bad, I guess I didn’t use forever properly.

This one, however, can’t work on frontity:

forever start node_modules/frontity/dist/commands.js serve --port 3001

For future references, I managed to get it up and running by running:

forever start -c "npx frontity serve" /full-path/to-frontity-folder/

(Use “./” for current folder)

This is however, simple solution which I couldn’t find nowhere.