Weitere ähnliche Inhalte Ähnlich wie nginx + uwsgi emperor + bottle (20) Kürzlich hochgeladen (20) nginx + uwsgi emperor + bottle2. 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
4. 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
5. 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:
6. 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>
7. 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;
}
}
9. Testing it
$ curl localhost/time-utc.json
{"unix": "1380577343.16", "str": "2013-09-30 21:42:23 UTC"}
10. 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