Hasan's Post

Tutorial repository

View on GitHub
7 July 2021

Deploying app in a linux server

by Hasan

## Setup the server

Adding new user

Logout from the server and login as this new user

SSH keybased authentication. Login without password

Disallow root login over ssh

Deploy a firewall

Get Application to the server

Creating requirement.txt

Copy project to server

Create Virtual Environment on server

Create Configuration file with all of our environment varaiable

Run the flask app inside the server

Run the application with nginx and gunicorn

nginx and gunicorn configuration

sudo ufw delete allow 5000
sudo ufw enable
sudo systemctl restart nginx

In gunicorn website it is said number of workers = (2 * number of cores) + 1

nproc --all

Monitor gunicorn

sudo apt install supervisor

Now we need to creae a configuration file for sudo

sudo vim /etc/supervisor/conf.d/flaskblog.conf

In the configuration file we will write following line

[program:flaskblog]
directory=/home/hasan/Flask_Blog
command=/home/hasan/Flask_Blog/venv/bin/gunicorn -w 3 run:app
user=hasan
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stderr_logfile=/var/log/flaskblog/flaskblog.err.log
stdout_logfile=/var/log/flaskblog/flaskblog.out.log

Buy domain name

    sudo certbot --nginx
    sudo certbot renew --dry-run

after first command ask some question. Number 2 Ridirect to secure site.

one can see that it will redirect to secure opiton of the file

* If we want to see __nginx__ we will see there is some issue. 
``` bash
nginx -t

if we want something to run every 30 Minutes in common business hours */30 9-17 * * 1-5 echo 'hello' >> /tmp/test.text

now with e command one can edit the command crontab -r remove all crontab

cronGuru is a website where you can test those cronjob

tags: