Last active
March 17, 2017 16:42
-
-
Save chivalry/b4bcf7696fcb840e3c992aa3a2fa1074 to your computer and use it in GitHub Desktop.
Ubuntu Flask Steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update | |
sudo apt-get install python3-pip python3-dev nginx | |
sudo -H pip3 install --upgrade pip | |
sudo -H pip3 install virtualenv | |
mkdir ~/myproject | |
cd ~/myproject | |
virtualenv myprojectenv | |
source myprojectenv/bin/activate | |
pip install gunicorn flask | |
vim ~/myproject/myproject.py | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "<h1 style='color:blue'>Hello There!</h1>" | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0') | |
python myproject.py | |
vim ~/myproject/wsgi.py | |
from myproject import app | |
if __name__ == "__main__": | |
app.run() | |
cd ~/myproject | |
gunicorn --bind 0.0.0.0:5000 wsgi:app | |
deactivate | |
sudo vim /etc/systemd/system/myproject.service | |
[Unit] | |
Description=Gunicorn instance to serve myproject | |
After=network.target | |
[Service] | |
User=ubuntu | |
Group=www-data | |
WorkingDirectory=/home/ubuntu/myproject | |
Environment="PATH=/home/ubuntu/myproject/myprojectenv/bin" | |
ExecStart=/home/ubuntu/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app | |
[Install] | |
WantedBy=multi-user.target | |
sudo systemctl start myproject | |
sudo systemctl enable myproject | |
sudo vim /etc/nginx/sites-available/myproject | |
server { | |
listen 80; | |
server_name server_domain_or_IP; | |
location / { | |
include proxy_params; | |
proxy_pass http://unix:/home/ubuntu/myproject/myproject.sock; | |
} | |
} | |
sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled | |
sudo nginx -t | |
sudo rm /etc/nginx/sites-enabled/default | |
sudo systemctl restart nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment