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 01 of 03

  • root
  • August 21, 2019
  • 2 minute read

Overview

This tutorial will guide you in creating a simple Web/Flask Python application and deploy it on an NGINX server with uWSGI and uWSGI Emperor. This part 1 covers the installation of the required packages. It will install the following:

  • NGINX
  • uWSGI
  • uWSGI-Emperor
  • Flask

It will also cover creation of


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.

  • Virtual Environment
  • Installation of python packages via the requirements.txt

 

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.

 

Verification

01. Verify that Python and Pip3 has been installed


$ python -V

# or

$ python3 -V

$ pip -V

# or

$ pip3 -V

 

Setup the Python Virtual Environment

01. Create the python virtual environment. In this example we are creating the environment on the user’s home directory. But you can change its location depending on your preference.

$ cd ~/

$ python3 -m venv geek-venv

 

02. Go to the virtual environment directory

$ cd geek-venv/bin

 

03. Under the /bin directory activate the virtual environment using the source command. This will activate the virtual environment


$ source activate

 

04. Once the virtual environment is activated, use pip command to install the python packages required by your app.


(geek-venv) ubuntu@{host}:~/geek-venv/bin$ pip install --upgrade pip

 

05. To verify that the libraries has been installed execute the command below and verify the versions installed.


(geek-venv) ubuntu@{host}:~/geek-venv/bin$ pip freeze

 

06. To deactivate the virtual environment, type deactivate


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

 

uWSGI Installation

01. Install uwsgi.


$ sudo apt-get update

$ sudo apt-get install build-essential -y

# Minimal Install (Recommended for Production Environment)

$ sudo apt-get install uwsgi uwsgi-plugin-python3 -y

# Complete Install (Generally used for Development Environment)

$ sudo apt-get install uwsgi uwsgi-extra uwsgi-plugins-all uwsgi-plugin-python3 -y

 

Read More  LPython: Novel, Fast, Retargetable Python Compiler

02. Check and verify the installation


$ uwsgi --version


Note: The packages uwsgi-extra and uwsgi-plugins-all are optional packages that ensures that all uwsgi packages are needed during development and might not be needed during production deployments.

 

03. Install the uwsgi emperor.

Note: Normally, uwsgi is enough for running single app deployment, but we use emperor mode for running single and multi-app deployments. It is a special uWSGI instance that will monitor specific events and will spawn/stop/reload instances on demand.


$ sudo apt-get install uwsgi-emperor -y

 

INFO: uWSGI Directories

Below are the uWSGI directories you have to be wary of, as some of them are the ones you will be troubleshooting if there are any problems.


# uWSGI file system

  ## Default root configuration

    /usr/share/uwsgi/conf/default.ini

  ## Configuration location for applications

    /etc/uwsgi/apps-available

    /etc/uwsgi/apps-enabled


# uWSGI (Emperor) file system

  ## Default root configuration

    /etc/uwsgi-emperor/emperor.ini

  ## Configuration location for applications

    /etc/uwsgi-emperor/vassals

  ## Logs

    /var/log/uwsgi/emperor.log

  ## Socket

    /var/run/

 

Nginx Installation

01. Install the nginx.


# Minimal Install (Recommended for Production Environment)

$ sudo apt-get install nginx nginx-extras

# Complete Install (Generally used For Development Environment)

$ sudo apt-get install nginx-full

 

02. Verify if NGINX is installed


$ nginx -V

It should show the NGINX version. Sample is below:


nginx version: <b>nginx/1.14.0 (Ubuntu)</b>

built with OpenSSL 1.1.0g  2 Nov 2017

TLS SNI support enabled

configure arguments:

...

 

03. To test if nginx is working.


$ curl http://localhost

 

04. Remove the default nginx configuration. After the following has been executed, the curl http://localhost command will return a connection refused. We will fix this in the next guide.


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

$ sudo service nginx restart

 

Read More  The Best New Tech Talent May Not Be Where You Think: A Guide To Hiring From Universities in 2021

Appendix

uWSGI commands

Start uwsgi-emperor.


$ sudo service uwsgi-emperor start

 

Restart uwsgi-emperor.


$ sudo service uwsgi-emperor restart

 

Stop uwsgi-emperor.


$ sudo service uwsgi-emperor stop

 

Installation Shell Script


#!/bin/bash

# Execute this script in sudo, and in the user home directory

# Tested on: Ubuntu 18.04

# Update the repository

apt-get update

# Python, PIP and VirtualEnv

apt-get install python3 -y

apt-get install python3-dev -y

apt-get install python3-pip -y

apt-get install python3-venv -y


# Create a Python Virtual Environment and install flask and django

mkdir ~/geek-venv/

python3 -m venv /geek-venv/python3-venv

~/geek-venv/bin/pip3 install --upgrade pip


# uWSGI Installation

apt-get install build-essential

apt-get install uwsgi uwsgi-plugin-python3 -y

apt-get install uwsgi-emperor -y


# NGINX Installation

apt-get install nginx nginx-extras -y

 

To continue with the configuration, click 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
  • Flask
  • How To
  • Installation
  • NGINX
  • Python
  • uWSGI
  • Web
You May Also Like
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
View Post
  • Programming
  • Public Cloud

Buffer HTTP Requests With Cloud Tasks

  • May 4, 2023
View Post
  • Programming
  • Public Cloud
  • Software
  • Software Engineering

Learn About Google Cloud’s Updated Renderer For The Maps SDK For Android

  • May 4, 2023

Stay Connected!
LATEST
  • What is cloud bursting?
    • June 18, 2025
  • What is confidential computing?
    • June 17, 2025
  • Oracle adds xAI Grok models to OCI
    • June 17, 2025
  • Fine-tune your storage-as-a-service approach
    • June 16, 2025
  • 5
    Advanced audio dialog and generation with Gemini 2.5
    • June 15, 2025
  • 6
    A Father’s Day Gift for Every Pop and Papa
    • June 13, 2025
  • 7
    Global cloud spending might be booming, but AWS is trailing Microsoft and Google
    • June 13, 2025
  • Google Cloud, Cloudflare struck by widespread outages
    • June 12, 2025
  • What is PC as a service (PCaaS)?
    • June 12, 2025
  • 10
    Apple services deliver powerful features and intelligent updates to users this autumn
    • June 11, 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
    Crayon targets mid-market gains with expanded Google Cloud partnership
    • June 10, 2025
  • By the numbers: Use AI to fill the IT skills gap
    • June 11, 2025
  • 3
    Apple supercharges its tools and technologies for developers to foster creativity, innovation, and design
    • June 9, 2025
  • Apple-WWDC25-Apple-Intelligence-hero-250609 4
    Apple Intelligence gets even more powerful with new capabilities across Apple devices
    • June 9, 2025
  • Apple-WWDC25-Liquid-Glass-hero-250609_big.jpg.large_2x 5
    Apple introduces a delightful and elegant new software design
    • June 9, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.