centos
Installing
yum groupinstall "Development Tools"
python-devel
python-pip
pip install
virtualenv
mkdir wsgi
cd wsgi
virtualenv db_venv
mkdir app
source
db_venv/bin/activate
type deactivate to exitpip install uwsgi
create wsgi
application inside wsgi folder
def application(env, start_response):start_response('200 OK', [('Content-Type', 'text/html')])return ["Hello!"]
uwsgi --socket 127.0.0.1:8080 --protocol=http -w wsgi
To run the server in the
background, run the following:uwsgi --socket 127.0.0.1:8080 --protocol=http -w wsgi &
Configuring Nginx,
make sure to remove --protocol=http
from the chain of arguments,test:
Stopping the server with SIGINT
kill
-INT [PID]
Configure
a uWSGI Config File
Deactive
from virtualenvironmentnano
wsgi.ini[uwsgi]module = wsgi:applicationmaster = trueprocesses = 5socket = myapp.sockchmod-socket = 664vacuum = truedie-on-term = true
vacuum
option, which will remove the socket when the process stops:die-on-term
so that uWSGI will kill the process instead of reloading it:
Create an Upstart File to Manage the App
sudo nano /etc/init/myapp.conf
description "uWSGI instance to serve myapp"start on runlevel [2345]stop on runlevel [!2345]setuid demosetgid www-datascriptcd /home/demo/myapp. myappenv/bin/activateuwsgi --ini myapp.iniend script
setuid
and setgidweb
server needs to be able to read and write to the socket that our .ini
file will create:sudo start myappsudo stopmyappuwsgi --ini myapp.ini![]()
Configure
Nginx to Proxy to uWSGI
sudo nano /etc/nginx/sites-available/myappserver {listen 80;server_name server_domain_or_IP;location / {include uwsgi_params;uwsgi_pass unix:/home/demo/myapp/myapp.sock;}}
No comments:
Post a Comment