-
Notifications
You must be signed in to change notification settings - Fork 7
Flask
alochym01 edited this page May 6, 2018
·
9 revisions
- python 3.6.4
- version 0.12
- gunicorn 19.8.1
- Install pyenv installer
-
Install pyenv
- create virtual python directory
python -m venv pyflask
- using python virtual environment
source /home/hadn/pyflask/bin/activate
- Install flask and nginx
- pip install flask flask-migrate flask-debugtoolbar flask-login flask-sqlalchemy psycopg2-binary flask-wtf gunicorn
- yum install -y nginx
- download and untar source code
- wget https://github.com/alochym01/freeswitch_flask_gui/archive/0.3.tar.gz
- tar -xvf 0.3.tar.gz
- Configuration
- run all requirement steps
export DATABASE_URL="postgresql://freeswitch:[email protected]:5432/freeswitch"
export FLASK_APP=freeswitch.py
flask db init
flask db migrate
flask db upgrade
flask initdb
sudo gpasswd --add nginx hadn
sudo chmod 710 /home/hadn
vi config.py
SQLALCHEMY_DATABASE_URI = "postgresql://freeswitch:[email protected]:5432/freeswitch"
- Using flask, gunicorn, nginx and systemd
- systemd
vi /etc/systemd/system/flaskapp.service
[Unit]
Description = Flask GUI for Freeswitch
After = network.target postgresql-9.6.service redis.service
[Service]
PermissionsStartOnly = true
PIDFile = /run/flask_app/flask_app.pid
User = hadn
Group = hadn
WorkingDirectory = /home/hadn/freeswitch_flask_gui-0.3
ExecStartPre = /bin/mkdir /run/flask_app
ExecStartPre = /bin/chown -R hadn:hadn /run/flask_app
ExecStart = /home/hadn/pyflask/bin/gunicorn freeswitch:app -b 127.0.0.1:8000 -w 4 --pid /run/flask_app/flask_app.pid
ExecReload = /bin/kill -s HUP $MAINPID
ExecStop = /bin/kill -s TERM $MAINPID
ExecStopPost = /bin/rm -rf /run/flask_app
PrivateTmp = true
[Install]
WantedBy = multi-user.target
- nginx
server {
# listen on port 80 (http)
listen 80;
server_name _;
location / {
# redirect any requests to the same URL but on https
return 301 https://$host$request_uri;
}
}
server {
# listen on port 443 (https)
listen 443 ssl;
server_name _;
# location of the self-signed SSL certificate
ssl_certificate /home/ubuntu/microblog/certs/cert.pem;
ssl_certificate_key /home/ubuntu/microblog/certs/key.pem;
# write access and error logs to /var/log
access_log /var/log/microblog_access.log;
error_log /var/log/microblog_error.log;
location / {
# forward application requests to the gunicorn server
proxy_pass http://localhost:8000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
# handle static files directly, without forwarding to the application
alias /home/hadn/freeswitch_flask_gui-0.3/flask_app/static;
expires 30d;
}
}