Skip to content

Instantly share code, notes, and snippets.

@doole
Last active July 14, 2016 03:59
Show Gist options
  • Save doole/1b187a16edc45fb9da54 to your computer and use it in GitHub Desktop.
Save doole/1b187a16edc45fb9da54 to your computer and use it in GitHub Desktop.
Flask deployment on Debian Jessie

Flask deployment on Debian Jessie

Software

Setup

gunicorn

  • /etc/systemd/system/gunicorn.service
  • /etc/systemd/system/gunicorn.socket
  • /etc/tmpfiles.d/gunicorn.conf

nginx

  • /etc/nginx/sites-available/app
# nginx
upstream app_server {
server unix:/run/gunicorn/socket fail_timeout=0;
}
server {
listen 80;
server_name _;
location / {
try_files $uri @proxy_to_app;
}
location /static {
alias /home/user/app/static;
}
access_log /var/log/nginx/app_access.log;
error_log /var/log/nginx/app_error.log;
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://app_server;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
}
d /run/gunicorn 0755 www-data www-data -
[Unit]
Description=app gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
PIDFile=/run/gunicorn/pid
User=www-data
Group=www-data
WorkingDirectory=/home/user/app
ExecStart=/home/user/app/env/bin/gunicorn --workers 2 --pid /run/gunicorn/pid app:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[Unit]
Description=top music gunicorn socket
[Socket]
ListenStream=/run/gunicorn/socket
[Install]
WantedBy=sockets.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment