SlideShare a Scribd company logo
Simple webapps with nginx, uwsgi emperor and bottle
What is nginx
 HTTP and reverse proxy server
 Event driven

 Very fast
 Easy to configure
What is uWSGI
 WSGI compatible server
 VERY flexible

 Little overhead
 Compatible with many frameworks like: bottle, flask,
django, …
What is bottle
 Bottle is a fast, simple and lightweight WSGI web
microframework
 No additional dependencies
 Uses decorators: @route, @get, @post, etc…
Bottle Hello World
 mkdir –p /opt/uwsgiApps/apps/
 cd /opt/uwsgiApps/apps/

 virtualenv bottle-hello
 cd bottle-hello
 pip install bottle
Bottle Hello World
 vi bottle-hello.py:

from bottle import route, run
@route('/hello')
def hello():
return "Hello World!"
if __name__ == '__main__':
run(port=8080, debug=True)
else:
application = app
Bottle Hello World
 python bottle-hello.py
 Try to access http://localhost:8080/
Bottle Hello World v2
 Add this (after the initial imports) to bottle-hello.py:
from bottle import template
@route('/hello/<name>')
def greet(name='Stranger'):
return template('Hello {{name}}, how are you?', name=name)

 python bottle-hello.py
 Try to access http://localhost:8080/hello/yourname
uWSGI installation
 pip install uwsgi
 vi /etc/init/uwsgi.conf:
# uWSGI - manage uWSGI application server
description "uWSGI Emperor"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
respawn
env LOGTO=/var/log/uwsgi/uwsgi.log
env BINPATH=/usr/local/bin/uwsgi
exec $BINPATH --emperor /opt/uwsgiApps/conf.d/ --logto $LOGTO
uWSGI emperor
 One of many uWSGI configuration options
 One master process

 Many independent child processes
 Each application has a config file
 Touch or modify the config file to restart the
application
uWSGI example config
 vi /opt/uwsgiapps/conf.d/bottle-hello.xml:

<uwsgi>
<master>true</master>
<processes>1</processes>
<vaccum>true</vaccum>
<chmod-socket>600</chmod-socket>
<socket>/tmp/%n.sock</socket>
<uid>www-data</uid>
<gid>www-data</gid>
<pythonpath>/opt/uwsgiApps/apps/%n/src/</pythonpath>
<module>scatterapp</module>
</uwsgi>
nginx configuration
 vi /etc/nginx/conf.d/subdomain1.domain.com.conf:
server {
listen 80;
server_name subdomain1.domain.com.conf;

location / {
include uwsgi_params;
uwsgi_pass unix://tmp/bottle-example.py;
}
}
System overview


nginx acts as a reverse proxy



nginx redirects the requests based on the domain name or any other
parameter (ip address, url path, cookies, etc)



uWSGI starts and stops the applications



bottle is used to program the application
Questions
Links
 http://nginx.org/
 http://uwsgi-docs.readthedocs.org/

 http://bottlepy.org/

More Related Content

PPTX
nginx + uwsgi emperor + bottle
PDF
DevOps(3) : Ansible - (MOSG)
PDF
體驗 Hhvm
PDF
DevOps Series: Extending vagrant with Puppet for configuration management
PDF
Provisioning with Puppet
PDF
Instruction: dev environment
PPTX
Vagrant step-by-step guide for Beginners
PDF
DevOps(2) : Vagrant - (MOSG)
nginx + uwsgi emperor + bottle
DevOps(3) : Ansible - (MOSG)
體驗 Hhvm
DevOps Series: Extending vagrant with Puppet for configuration management
Provisioning with Puppet
Instruction: dev environment
Vagrant step-by-step guide for Beginners
DevOps(2) : Vagrant - (MOSG)

What's hot (19)

PDF
Create your very own Development Environment with Vagrant and Packer
PDF
Making environment for_infrastructure_as_code
PDF
Docker command
PDF
Speed up your development environment PHP + Nginx + Fedora + PG
PPTX
PPTX
6 Years of Docker: The Good, the Bad and Python Packaging at PyCon.DE&PyData ...
PPT
Node.js Cloud deployment
PDF
Docker puppetcamp london 2013
PPTX
Python+anaconda Development Environment
PDF
Backing up thousands of containers
PPTX
Build & test Apache Hawq
PDF
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
PDF
Dev ops
PPTX
Dockercon - Building a Chef cookbook testing pipeline with Drone.IO and Docker
PPTX
Docker 101 & Workshop
PDF
Cialug August 2021
PDF
Docker perl build
PPTX
Archlinux dev environment
Create your very own Development Environment with Vagrant and Packer
Making environment for_infrastructure_as_code
Docker command
Speed up your development environment PHP + Nginx + Fedora + PG
6 Years of Docker: The Good, the Bad and Python Packaging at PyCon.DE&PyData ...
Node.js Cloud deployment
Docker puppetcamp london 2013
Python+anaconda Development Environment
Backing up thousands of containers
Build & test Apache Hawq
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
Dev ops
Dockercon - Building a Chef cookbook testing pipeline with Drone.IO and Docker
Docker 101 & Workshop
Cialug August 2021
Docker perl build
Archlinux dev environment
Ad

Viewers also liked (10)

PPTX
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
PDF
Symantec 2011 CIP Survey Global Results
PPTX
uWSGI - Swiss army knife for your Python web apps
PPTX
Getting Started with ASP.net Core 1.0
PDF
nginx入門
PPTX
An Introduction to OAuth 2
PDF
Scalable Django Architecture
PPTX
ASP.NET Core 1.0 Overview
PDF
Access Control Presentation
PDF
containerd and CRI
EuroPython 2014 - How we switched our 800+ projects from Apache to uWSGI
Symantec 2011 CIP Survey Global Results
uWSGI - Swiss army knife for your Python web apps
Getting Started with ASP.net Core 1.0
nginx入門
An Introduction to OAuth 2
Scalable Django Architecture
ASP.NET Core 1.0 Overview
Access Control Presentation
containerd and CRI
Ad

Similar to Simple webapps with nginx, uwsgi emperor and bottle (20)

PPTX
Nginx-deploy on linux server with 80 and 442
PDF
Free django
PPTX
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
PDF
Guideline paper@rpi full_stack_python_arch
PDF
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
KEY
The story and tech of Read the Docs
PDF
Batteries not included
PPTX
NGINX: Basics & Best Practices - EMEA Broadcast
PDF
WSGI, Django, Gunicorn
PDF
What The Flask? and how to use it with some Google APIs
PPTX
flask frameworkbasedonPython_microframework.pptx
PDF
Behind the curtain - How Django handles a request
PDF
App Engine
PDF
NGINX: Basics and Best Practices EMEA
PPTX
Python Code Camp for Professionals 2/4
PPTX
PDF
Flask Introduction - Python Meetup
PDF
CollegeDiveIn presentation
PDF
Django for mobile applications
KEY
Nginx - Tips and Tricks.
Nginx-deploy on linux server with 80 and 442
Free django
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Guideline paper@rpi full_stack_python_arch
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
The story and tech of Read the Docs
Batteries not included
NGINX: Basics & Best Practices - EMEA Broadcast
WSGI, Django, Gunicorn
What The Flask? and how to use it with some Google APIs
flask frameworkbasedonPython_microframework.pptx
Behind the curtain - How Django handles a request
App Engine
NGINX: Basics and Best Practices EMEA
Python Code Camp for Professionals 2/4
Flask Introduction - Python Meetup
CollegeDiveIn presentation
Django for mobile applications
Nginx - Tips and Tricks.

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
KodekX | Application Modernization Development
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KodekX | Application Modernization Development
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation_ Review paper, used for researhc scholars
Per capita expenditure prediction using model stacking based on satellite ima...
Chapter 3 Spatial Domain Image Processing.pdf
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The AUB Centre for AI in Media Proposal.docx

Simple webapps with nginx, uwsgi emperor and bottle

  • 2. What is nginx  HTTP and reverse proxy server  Event driven  Very fast  Easy to configure
  • 3. What is uWSGI  WSGI compatible server  VERY flexible  Little overhead  Compatible with many frameworks like: bottle, flask, django, …
  • 4. What is bottle  Bottle is a fast, simple and lightweight WSGI web microframework  No additional dependencies  Uses decorators: @route, @get, @post, etc…
  • 5. Bottle Hello World  mkdir –p /opt/uwsgiApps/apps/  cd /opt/uwsgiApps/apps/  virtualenv bottle-hello  cd bottle-hello  pip install bottle
  • 6. Bottle Hello World  vi bottle-hello.py: from bottle import route, run @route('/hello') def hello(): return "Hello World!" if __name__ == '__main__': run(port=8080, debug=True) else: application = app
  • 7. Bottle Hello World  python bottle-hello.py  Try to access http://localhost:8080/
  • 8. Bottle Hello World v2  Add this (after the initial imports) to bottle-hello.py: from bottle import template @route('/hello/<name>') def greet(name='Stranger'): return template('Hello {{name}}, how are you?', name=name)  python bottle-hello.py  Try to access http://localhost:8080/hello/yourname
  • 9. uWSGI installation  pip install uwsgi  vi /etc/init/uwsgi.conf: # uWSGI - manage uWSGI application server description "uWSGI Emperor" start on (filesystem and net-device-up IFACE=lo) stop on runlevel [!2345] respawn env LOGTO=/var/log/uwsgi/uwsgi.log env BINPATH=/usr/local/bin/uwsgi exec $BINPATH --emperor /opt/uwsgiApps/conf.d/ --logto $LOGTO
  • 10. uWSGI emperor  One of many uWSGI configuration options  One master process  Many independent child processes  Each application has a config file  Touch or modify the config file to restart the application
  • 11. uWSGI example config  vi /opt/uwsgiapps/conf.d/bottle-hello.xml: <uwsgi> <master>true</master> <processes>1</processes> <vaccum>true</vaccum> <chmod-socket>600</chmod-socket> <socket>/tmp/%n.sock</socket> <uid>www-data</uid> <gid>www-data</gid> <pythonpath>/opt/uwsgiApps/apps/%n/src/</pythonpath> <module>scatterapp</module> </uwsgi>
  • 12. nginx configuration  vi /etc/nginx/conf.d/subdomain1.domain.com.conf: server { listen 80; server_name subdomain1.domain.com.conf; location / { include uwsgi_params; uwsgi_pass unix://tmp/bottle-example.py; } }
  • 13. System overview  nginx acts as a reverse proxy  nginx redirects the requests based on the domain name or any other parameter (ip address, url path, cookies, etc)  uWSGI starts and stops the applications  bottle is used to program the application