Skip to content

Instantly share code, notes, and snippets.

@mihkels
Last active October 24, 2022 19:20
Show Gist options
  • Save mihkels/5461669 to your computer and use it in GitHub Desktop.
Save mihkels/5461669 to your computer and use it in GitHub Desktop.
Ubuntu 12.04 with flask + nginx + uwsgi
#!/bin/bash
sudo apt-get update
# Now let's install all the required ubuntu packages
sudo apt-get install build-essential uwsgi nginx uwsgi-plugin-python python-pip
# PS! If you are doing this stuff for fun I do recommend to install nginx from PPA repository
# that you can find here https://launchpad.net/~nginx/+archive/development
# Now let's install virtualenv
sudo pip install virtualenv
#!/bin/bash
PROJECT_BASE=$HOME/projects/webapp
# Now we setup our sample website and virtual env
mkdir $PROJECT_BASE
mkdir $PROJECT_BASE/static
sudo virtualenv $PROJECT_BASE/env
# now we install Flask into our virtualenv
source $PROJECT_BASE/env/bin/activate
sudo pip install flask
deactivate
# Now we can create Nginx and uWSGI configuration files
SERVER_CONF=/etc/nginx/sites-available
APP=mywebapp
sudo touch $SERVER_CONF/$APP
sudo touch /etc/uwsgi/app-avialable/$APP.ini
sudo ln -s $SERVER_CONF/$APP /etc/nginx/sites-enabled
sudo ln -s /etc/uwsgi/app-available/$APP.ini /etc/uwsgi/app-enabled
server {
listen 80;
server_name mywebapp;
location /static {
alias /home/user/projects/mywebapp/static;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/mywebapp.sock;
uwsgi_param UWSGI_PYHOME /home/user/projects/mywebapp/env;
uwsgi_param UWSGI_CHDIR /home/user/projects/mywebapp;
uwsgi_param UWSGI_MODULE mywebapp;
uwsgi_param UWSGI_CALLABLE app;
}
error_page 404 /404.html;
}
[uwsgi]
plugins=python
vhost=true
socket=/tmp/mywebapp.sock
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment