nginx + uwsgi emperor + bottle

3,190 views

Published on

How to easily create a nginx, uwsgi emperor and bottle deployment.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,190
On SlideShare
0
From Embeds
0
Number of Embeds
37
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

nginx + uwsgi emperor + bottle

  1. 1. Package Installation  As root:  Install nginx repository:  Install nginx packages: echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu precise main" > /etc/apt/sources.list.d/nginx.list apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C apt-get update apt-get install nginx python-pip python-dev build-essential pip install virtualenv pip install uwsgi pip install bottle
  2. 2. Now the fun part starts
  3. 3. Configure uWSGI emperor  Create /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
  4. 4. Create a simple test app mkdir -p /opt/uwsgiApps/conf.d/ mkdir -p /opt/uwsgiApps/apps/simpleTestApp/ import json import time from datetime import datetime import bottle @bottle.route('/time-utc.json') def utc_time(): ts = { 'unix': str(time.time()), 'str': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC") } return json.dumps(ts) if __name__ == '__main__': bottle.run(bottle.default_app(), host='0.0.0.0', port=80, reloader=True) else: application = bottle.default_app()  /opt/uwsgiApps/apps/simpleTestApp/bottleMain.py:
  5. 5. uWSGI app config  /opt/uwsgiApps/conf.d/simpleTestApp.xml: <uwsgi> <master>true</master> <processes>1</processes> <vaccum>true</vaccum> <chmod-socket>666</chmod-socket> <socket>/tmp/%n.sock</socket> <uid>www-data</uid> <gid>www-data</gid> <pythonpath>/opt/uwsgiApps/apps/%n</pythonpath> <module>bottleMain</module> </uwsgi>
  6. 6. nginx config file  /etc/nginx/conf.d/simpleTestApp.conf: config nginx: server { listen 80; server_name your-url.com; location / { include uwsgi_params; uwsgi_modifier1 30; uwsgi_pass unix://tmp/simpleTestApp.sock; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
  7. 7. Let’s start it service uwsgi start service nginx restart
  8. 8. Testing it $ curl localhost/time-utc.json {"unix": "1380577343.16", "str": "2013-09-30 21:42:23 UTC"}
  9. 9. Random stuff  Whenever a uWSGI configuration file is touched the app is restarted  Adding another app is as simple as dumping the files in the right place  As soon as we write the uWSGI configuration file it will try to load the application  It is possible to use other this with microframeworks like Flask
  10. 10. Questions?

×