aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Programming

How To Create A Simple Python Web App Using NGINX, uWSGI, And Flask – Part 03 of 03

  • root
  • August 23, 2019
  • 2 minute read

Overview

This is the 2nd part of the 3-part guide on Installing, Configuring and Deploying a Python Web/Flask application on an Ubuntu system that uses NGINX and uWSGI. For the installation part go here. For the configuration part go here.

 


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

Prerequisites

  • Ubuntu 18.04
  • Python 3.x has been installed. For instructions see here.
  • Pip and Virtual Environment has been installed. For instructions see here.
  • Installed NGINX, uWSGI, and uWSGI-Emperor from previous guides.
  • Configured NGINX, uWSGI and uWSGI-Emperor from previous guides.

 

Deploy a Flask App/API using uWSGI and NGINX

Note: For this demo, we used the sample flask app and a python virtual environment. And it will be located under /var/www

01. Create the following directories and files

Directories and file structure


|__ /var/www

  |__ geek_flask_app

    |__ api

      |__ __init__.py

      |__ res

        |__ __init__.py

        |__ endpoints.py

    |__ app_wsgi.py

    |__ requirements.txt

 

Or create the files and directories using the following commands


$ cd /var/www

$ sudo mkdir -p geek_flask_app/api/res

 

/var/www/geek_flask_app/api/__init__.py content


from flask import Flask

application = Flask(__name__)

import api.res.endpoints

 

/var/www/geek_flask_app/app_wsgi.py

from api import application

 

/var/www/geek_flask_app/api/res/endpoints.py


# -*- coding: utf-8 -*-

from flask import jsonify
from api import application

@application.route('/', methods=['GET'])
def get_app_properties():
  name = 'geek-flask-api'
  version = '0.0.1'

  app_properties = \
  {
    'name': name
    , 'version' : version
  }

  return jsonify(app_properties)

 

/var/www/geek_flask_app/requirements.txt

flask

 

02. Install python libraries that is required by your application.

Note: Since we are using a virtual environment, activate the virtual environment and install the python libraries. See the Setup the Python Virtual Environment section.

$ source ~/geek-venv/bin/activate

(geek-venv) ubuntu@{host}:~$ cd /var/www/flask_app

(geek-venv) ubuntu@{host}:~$ pip install -r requirements.txt

(geek-venv) ubuntu@{host}:~$ deactivate

 

03. Reload the uwsgi-emperor service.

$ sudo service uwsgi-emperor reload

 

Read More  Tips For Building A Quality App With Firebase

04. To verify if the flask app is deployed, test using the http-socket defined in uwsgi configuration.

$ curl http://127.0.0.1:8081

 

It should return a JSON structured response

{"name":"geek-flask-api","version":"0.0.1"}

 

05. Next is to verify if NGINX can communicate with our Python Flask app on uWSGI. Restart the NGINX server

$ sudo service nginx restart

 

06. Verify using cURL on the NGINX.

$ curl http://localhost

 

It should also show the same response

{"name":"geek-flask-api","version":"0.0.1"}

 

Next steps is to configure your DNS and map it to your NGINX configuration. And you should next configure the previously commented gid and uid to use the proper user, an example is “www-data”.

Click here for Part 01 and here for Part 02.


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

root

Related Topics
  • App Deployment
  • Flask
  • How To
  • NGINX
  • Python
  • uWSGI
You May Also Like
aster-cloud-sms-pexels-tim-samuel-6697306
View Post
  • Programming
  • Software

Send SMS texts with Amazon’s SNS simple notification service

  • July 1, 2025
aster-cloud-website-pexels-goumbik-574069
View Post
  • Programming
  • Software

Host a static website on AWS with Amazon S3 and Route 53

  • June 27, 2025
View Post
  • Architecture
  • Data
  • Engineering
  • People
  • Programming
  • Software Engineering
  • Technology
  • Work & Jobs

Predictions: Top 25 Careers Likely In High Demand In The Future

  • June 6, 2023
View Post
  • Programming
  • Software Engineering
  • Technology

Build a Python App to Alert You When Asteroids Are Close to Earth

  • May 22, 2023
View Post
  • Programming

Illuminating Interactions: Visual State In Jetpack Compose

  • May 20, 2023
View Post
  • Computing
  • Data
  • Programming
  • Software
  • Software Engineering

The Top 10 Data Interchange Or Data Exchange Format Used Today

  • May 11, 2023
View Post
  • Architecture
  • Programming
  • Public Cloud

From Receipts To Riches: Save Money W/ Google Cloud & Supermarket Bills – Part 1

  • May 8, 2023
View Post
  • Programming
  • Public Cloud

3 New Ways To Authorize Users To Your Private Workloads On Cloud Run

  • May 4, 2023

Stay Connected!
LATEST
  • How to create an AWS free tier account
    • July 10, 2025
  • How to configure multiple AWS CLI authentication credentials
    • July 10, 2025
  • Create an Amazon EKS cluster and deploy Docker containers
    • July 10, 2025
  • Get to know storage-as-a-service providers and their offerings
    • July 10, 2025
  • 5
    Formula E accelerates its work with Google Cloud Storage and Google Workspace
    • July 9, 2025
  • What is database as a service (DBaaS)?
    • July 7, 2025
  • The cloud’s role in PQC migration
    • July 7, 2025
  • 8
    Hybrid cloud has hit the mainstream – but firms are still confused about costs
    • July 7, 2025
  • 9
    Building secure, scalable AI in the cloud with Microsoft Azure
    • July 5, 2025
  • 10
    Turns out OpenAI is the customer behind Oracle’s mysterious $30 billion cloud deal
    • July 3, 2025
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • 1
    A looming hyperscaler exodus? UK IT leaders are thinking of ditching US cloud providers – here’s why
    • June 26, 2025
  • aster-cloud-erp-bill_of_materials_2 2
    What is an SBOM (software bill of materials)?
    • July 2, 2025
  • aster-cloud-sms-pexels-tim-samuel-6697306 3
    Send SMS texts with Amazon’s SNS simple notification service
    • July 1, 2025
  • Genome 4
    AlphaGenome: AI for better understanding the genome
    • June 25, 2025
  • aster-cloud-website-pexels-goumbik-574069 5
    Host a static website on AWS with Amazon S3 and Route 53
    • June 27, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.