Skip to main content

Run Flask apps as services and manage them with NGINX

Run Flask apps as services and manage them with NGINX 

sudo apt install python3-pip

sudo apt install nginx

sudo adduser --home=/opt/kobros --disabled-password --gecos "Kobros" kobros

sudo su - kobros

mkdir company_app

cd company_app

python3 -m venv py-env

source py-env/bin/activate

pip3 install gunicorn flask

nano app.py

-------------------------- FILE --------------------------

from flask import Flask

app = Flask(__name__)

@app.route(‘/’)
def hello_world():
     return "<center>Hello World! Uooohh Mantaapp</center>"
    
if __name__ == ‘__main__’:
     app.run(debug=True,host=’0.0.0.0')

------------------------------------------------------------

nano wsgi.py

-------------------------- FILE --------------------------

from app import app

if __name__ == “__main__”:
     app.run()

------------------------------------------------------------

python3 app.py

gunicorn --bind 0.0.0.0:5000 wsgi:app

deactivate

sudo nano /etc/systemd/system/company_app.service

-------------------------- FILE --------------------------

[Unit]
Description=App to serve my company website
After=network.target
[Service]
User=kobros
Group=kobros
WorkingDirectory=/opt/kobros/company_app
Environment=”PATH=/opt/kobros/company_app/py-env/bin”
ExecStart=/opt/kobros/company_app/py-env/bin/python3 /opt/kobros/company_app/py-env/bin/gunicorn wsgi:app
[Install]
WantedBy=multi-user.target

------------------------------------------------------------

sudo systemctl start company_app

sudo nano /etc/nginx/sites-available/company_app

-------------------------- FILE --------------------------

server {
    listen 80;
    listen [::]:80;

    location /company/ {
        include proxy_params;
        proxy_pass http://localhost:8000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /profile/ {
        include proxy_params;
        proxy_pass http://localhost:8001/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

------------------------------------------------------------

sudo rm /etc/nginx/sites-enabled/default

sudo ln -s /etc/nginx/sites-available/company_app /etc/nginx/sites-enabled

sudo nginx -t

systemctl restart nginx



Comments

Popular posts from this blog

Highlights on my contributions to Odoo Community Association

 Highlights on my contributions to Odoo Community Association For me as a developer working on odoo community and providing services to the customers using the community version of Odoo. Sometimes the solution is available in a module published by OCA that could be an older version of Odoo. As a result, I decided to put my upgraded modules on their repositories as a contributor, and I asked to join them on the mailing list. For them, before I start to make a pull request, I need to sign their ICLA document. ICLA means Odoo Community Association Individual Contributor License Agreement. To upgrade a module to version 17.0 I had to follow the instructions stated on: https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-17.0 Firstly this section: https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-17.0#before-migrating Which needs you to: (1)      Subscribe to OCA mailing list (2)     Sign ICLA as stated above (3)     Install precommit  as instructed here: https:

Use CS50 library in my local machine offline to run codes in C language

M ake your PC ready to run codes in C language How to use CS50 library in your local machine offline Here are three videos presented by someone, they will guide you to make your PC ready to run C files. How to Download and Install Visual Studio Code ( VS Code ) on Windows 10 How to Download and Install C Cpp Toolset ( gcc g++ gdb ) in Windows 10 using mingw-w64 and msys2 How to Set up Visual Studio Code for C and C++ Programming After watching the above videos and following the steps in them, you can apply the following steps in order to use CS50 library for implementing codes written in C language in your local machine offline. Download the zip file from Github Release,  https://github.com/cs50/libcs50/releases Unzip it, locate to libcs50/src/, you can get cs50.h and cs50.c Copy cs50.h and cs50.c in the Workspace Create and save a C file which uses cs50 libraries in the Workspace. We can call it hello.c, hello.c should be with cs50.h and cs50.c in the same folder in

Latest odoo module for logo printing business

 Latest odoo module for logo printing business  Elements: Product Attribute Model I can delete not critical attributes Can not delete critical attributes I can restore deleted [important] attributes Critical attributes have some critical values I can not delete critical values for critical attributes