Categories: Tips

Serving Flask helloworld using uwsgi

uwsgi is a high performance, low-resource usage web server for deploying python application.

In this post, i am going to show how to serve a simple HelloWorld application in flask using uwsgi

 

Prerequisites

pip install flask 

pip install uwsgi

Now lets create our app.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()


So we have created a simple flask application. Now lets create a run file for running the application

run.py

from app import app as application
if __name__ == "__main__":
    application.run()


Now we need to create a .ini (uwsgi.ini) file to save the settings for serving the uwsgi

[uwsgi]
http = 127.0.0.1:3031
chdir = /home/name/flaskuwsgi
wsgi-file = run.py
processes = 4
threads = 2
stats = 127.0.0.1:9191

now serve the application by running uwsgi uwsgi.ini. You can view your application at 127.0.0.1:3031

if you wish to serve it via nginx, configure reverse proxy to the ip and port after changing the first line in uwsgi.ini to

socket = 127.0.0.1:3031

Njoy smile

Mithun

Share
Published by
Mithun
Tags: flaskuwsgi

Recent Posts

Happy New Year 2024

Oh boy, there were a lot of things that happened this year. Like last year,…

1 week ago

Happy New Year 2023

This has become a abandoned blog. I will try to fix things this year. More…

1 year ago

Happy New Year 2022

Let me start off by saying, i have more blog posts this year than the…

2 years ago

Fix for xbox “This App Needs a Few Things That Are Missing on this PC”

This happened because your windows has run out of space. If you get this error…

2 years ago

Get back Windows 10 style start menu on Windows 11

Open the registry editor and navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_ShowClassicMode If Start_ShowClassicMode doesn't exist, create a new…

3 years ago

Enable second display HP omen ryzen with nvidia on Arch linux

My assumptions: You already have a screen or tty to perform the stepsYou installed arch…

3 years ago

This website uses cookies.