Just some quick notes on deploying your CRA using Nginx on Ubuntu 18.04 LTS
In the article “Using Certbot and Express.js to secure your CRA that uses React Hooks on Ubuntu 18” we used Node.js to deploy our CRA. In this article, we look at how we would deploy it using Nginx instead.
Installing Nginx
First of all we need to install nginx
sudo apt-get update
sudo apt-get install nginx
Check that the SSL port you plan to use is open:
sudo ufw statusStatus: activeTo Action From-- ------ ----443/tcp ALLOW Anywhere
Nginx configuration
Time to configure Nginx, go to the folder /etc/nginx, it looks like this:
sudi@hm-1:/etc/nginx$ tree -d.├── conf.d├── modules-available├── modules-enabled├── sites-available├── sites-enabled└── snippets
remove the default files in sites-available and sites-enabled. Instead, we create a new file called himinds.
We need to create a symbolic link to the sites-enabled folder
The syntax will look like this:
ln -s /etc/nginx/sites-available/MYDOMAIN /etc/nginx/sites-enabled/MYDOMAIN
Nginx commands
Some useful Nginx commands.
sudo service nginx startsudo service nginx stopsudo service status nginx
Deploy a new version of the CRA
So when we have updated our CRA based React app and want to deploy a new version we would run the following command in the himinds-boosting-innovation-web-secure-cra/hn-app/ folder:
npm run build
And then we need to restart Nginx
sudo service restart nginx
Thank you for reading! Take care and hope to see you soon. 🙏🏽
This article is a living document please reach out to me if you want to contribute or see anything inaccurate here. This article is part of our “Boosting Innovation” project.