Last active
December 29, 2020 20:29
-
-
Save realFranco/0ea6a1c708a39a996480a23ab35bf5e3 to your computer and use it in GitHub Desktop.
Recipe to deploy an React app using the environment: ubuntu, nginx, node, npm2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Steps to install the react Project | |
# Requirements: | |
# - ubuntu 18.04 ( I do not test it on 20.04 ). | |
# - git | |
# - Nginx | |
# - Node | |
# - pm2 | |
# - Certbot | |
# - Domain / Subdmain | |
# Install nginx | |
> sudo apt-get install nginx | |
# Install node | |
> curl -sL https://deb.nodesource.com/setup_current.x | sudo -E bash - | |
> sudo apt-get install -y nodejs | |
# Clone the repo | |
> git clone repo.git | |
# If the package manager it is yarn | |
> cd project_folder | |
# Install pm2 | |
# On the current folder of app | |
> npm install pm2@latest -g | |
# or | |
> yarn global add pm2 | |
# Lets encrypt - Free ssl domain | |
# Watch the next link and follow the steps | |
# Will be working only on: ubuntu 18.04 + nginx | |
# https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx | |
# Use yarn to start the project, without sudo | |
> yarn install | |
> yarn run start | |
> yarn build | |
# Development environment if you wish. | |
> sudo yarn start | |
# The command above run a script. | |
# Now, use pm2 command to start a demon on that script | |
> pm2 start my-app/node_modules/react-scripts/scripts/start.js --name "my-app" | |
# If you want a reverse proxy using nginx (this is missing some good practices) | |
> sudo nano /etc/nginx/sites-available/default | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
root /var/www/html; | |
index index.html index.htm index.nginx-debian.html; | |
server_name ip; # Public ip v4 from the host | |
listen 443 ssl; # managed by Certbot | |
# RSA | |
ssl_certificate /etc/letsencrypt/live/[subdomain.]domain.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/[subdomain.]domain.com/privkey.pem; | |
include /etc/letsencrypt/options-ssl-nginx.conf; | |
location / { | |
proxy_pass http://localhost:port; | |
} | |
} | |
# Check the syntax of the default file | |
> sudo nginx -t | |
# Restart the nginx service | |
> sudo service nginx restart | |
# If some problems detected while restarting nginx, check apache server. | |
# Stoped if they are listening request. | |
> sudo /etc/init.d/apache2 stop | |
# End. | |
# Disclaimer: | |
# The Certificate it is not inside of the cronjob. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment