9/15/17

Deploy aiohttp with gunicorn and nginx

sudo apt-get install python3 virtualenv supervisor

cd /home/user/aiohttp
virtualenv env --no-site-packages -p python3

source env/bin/activate

pip install aiohttp
pip install

nano gunicorn.conf.py

bind = "127.0.0.1:8081"
workers = 2
worker_class = "aiohttp.worker.GunicornWebWorker"

nano /etc/supervisor/conf.d/apptest.conf

[program:apptest]
command=/home/user/aiohttp/env/bin/gunicorn app_test:my_web_app -c /home/user/aiohttp/gunicorn.conf.py
directory=/home/user/aiohttp
user=nobody
autostart=true
autorestart=true

nano /etc/nginx/conf.d/apptest.conf

upstream apptest_server {
    server unix:/tmp/apptest.sock fail_timeout=0;
}

server {
    listen       80;
    server_name  192.168.1.10;

    root /home/user/aiohttp/static;

    location / {
      try_files $uri @proxy_to_app;
    }

    location @proxy_to_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://127.0.0.1:8081;
    }
}

service supervisor restart
service nginx restart

No comments:

Post a Comment