Last active
October 24, 2022 19:20
-
-
Save mihkels/5461669 to your computer and use it in GitHub Desktop.
Ubuntu 12.04 with flask + nginx + uwsgi
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
#!/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 |
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
#!/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 | |
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
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; | |
} |
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
[uwsgi] | |
plugins=python | |
vhost=true | |
socket=/tmp/mywebapp.sock |
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
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