Created
April 27, 2021 00:03
-
-
Save LuisHCK/4441e9c31b8c27e9c98626ef6a52aa42 to your computer and use it in GitHub Desktop.
Setup ubuntu server + nodejs + nginx + pm2 + certbot
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
# Install nodejs | |
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash - | |
sudo apt-get install -y nodejs | |
node --version | |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - | |
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list | |
sudo apt update && sudo apt install yarn | |
yarn --version | |
# Install certbot | |
sudo snap install core; sudo snap refresh core | |
sudo snap install --classic certbot | |
sudo ln -s /snap/bin/certbot /usr/bin/certbot | |
# Install nginx | |
sudo apt install nginx | |
# Install PM2 | |
sudo npm install pm2@latest -g | |
pm2 startup | |
# Nginx settings | |
NGINX_SETTINGS=" | |
upstream trivia_server_upstream { | |
server 127.0.0.1:4000; | |
keepalive 64; | |
} | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name api.conocenicaragua.xyz; | |
location / { | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header Host $http_host; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_pass http://trivia_server_upstream/; | |
proxy_redirect off; | |
proxy_read_timeout 240s; | |
} | |
location /mysocket/ { | |
proxy_pass http://trivia_server_upstream/; | |
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; | |
} | |
} | |
" | |
sudo echo $NGINX_SETTINGS > /etc/nginx/sites-available/default | |
sudo service nginx restart | |
sudo certbot --nginx --non-interactive --agree-tos -m luisjcenteno17@@gmail.com --domains api.conocenicaragua.xyz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment