Run Python Webserver

Run Python Webserver

Create Directory

mkdir /home/pytom
cd /home/pytom
pip install virtualenv
source /home/pytom/venv/bin/activate
pip install flask

Create main.py

vi main.py

from flask import Flask
app = Flask(__name__)
@app.route("/")

def index():
    return " Hallo Tom "

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=8083, debug=True)

Create app.yaml

Just 1 line

vi app.yaml
runtime: python39

Create requirements.txt

just 1 line

vi requirements.txt
Flask==2.0.2

save this files in /home/pytom

Run the Server

source /home/pytom/venv/bin/activate
cd /home/pytom
#export FLASK_APP=pytom
python main.py

Configuration on nginx.conf file for my domain

nginx.conf

 location /pytom/ {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8083/;
        proxy_http_version 1.1;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 600s;
        proxy_connect_timeout 600s;
        proxy_buffering on;
        proxy_buffer_size 16k;
        proxy_busy_buffers_size 24k;
        proxy_buffers 64 4k;
        keepalive_timeout 650;
    }

Access on Webbrowser:

https://test.domain.at/pytom/

Works!