React + Node + Nginx with Plesk. Part 1.

ZenBit Tech
3 min readJan 26, 2019

--

This article describes how to deploy the application on Plesk. What problems was faced and how to deal with them.

Suppose you have connected a domain.

Let’s start with connecting the NodeJS server, since this part took the most time to figure out the settings.

Firstly, you’ll have to install Git and NodeJs extension

Plesk supports ssh authentication only, consider it when you clone your application code.

Click NPM install install first. This will install all you project modules.

The subdomain api.domain_name was created for the server and the root folder was httpdocs/api

The first difficulty that we’ve encountered was that the server did not start via `node server.js`, but through `node -r dotenv / config start.js dotenv_config_path =. / Prod.env`, where the .env file contains all environment variables. Unfortunately, it was not possible to do it via the extension, as run script button always fall(share your experience in the comments if you have one). We decided that we will add environment variables via `Custom environment variables` — the appropriate settings field

But then another problem surfaced. The server start but not work and the logs can not be viewed in real mode. The pm2 library is great for this, but you cannot install it via the UI. Next changes are taking place in the terminal.

Server files are located in /var/www/vhosts/domain_name/ (official documentation https://docs.plesk.com/en-US/onyx/administrator-guide/web-hosting/website-directory-structure.68695/), in our case /var /www/vhosts/domain_name/httpdocs/api /

Install the pm2 library in the terminal — npm i pm2 -g

Then a second problem that we had `pm2 start npm — start` did not work . The pm2 version was the last and the command worked perfectly on another server. The only solution was to run through `pm2 start start.js`, but again, the environment variables in this case are not pulled. pm2 allows you to run the server with the settings (https://pm2.io/doc/en/runtime/guide/ecosystem-file/). In the root folder of the Nodov server, create the file ecosystem.config.js, with the following contents:

module.exports = {
apps : [{
name: “app”,
script: “./start.js”,
env: {
NODE_ENV: “prod”,
PORT:8080,
{YOUR_OTHER_VARIAVLES}
}
}]
}

And run the `pm2 start` command.

Finally, the server starts on port 8080. And `pm2 logs` allows you to see the logs in real time.

The only thing that is left is to configure nginx so that you can access the server because currently it is not accessible from the outside. Go to the Apache & nginx settings

At the very bottom find ‘Additional nginx directives’ field and add:

Now the server is available at http://subdomain_name

In the next part we will connect ssl certificates to this server. (https://medium.com/@zenbit_tech/react-node-nginx-with-plesk-part-2-dc7aa97a9b9e)

--

--

ZenBit Tech
ZenBit Tech

Written by ZenBit Tech

Custom software and cloud Solutions | Data engineering Talks about #medtech, #appdevelopment and #softwaredevelopment

Responses (1)