Skip to content

Instantly share code, notes, and snippets.

@touchmenot
Forked from mihkels/1-req.sh
Created January 6, 2014 22:01
Show Gist options
  • Select an option

  • Save touchmenot/8290572 to your computer and use it in GitHub Desktop.

Select an option

Save touchmenot/8290572 to your computer and use it in GitHub Desktop.

Revisions

  1. @mihkels mihkels revised this gist Apr 25, 2013. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  2. @mihkels mihkels created this gist Apr 25, 2013.
    20 changes: 20 additions & 0 deletions mywebapp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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;

    }
    4 changes: 4 additions & 0 deletions mywebapp.ini
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    [uwsgi]
    plugins=python
    vhost=true
    socket=/tmp/mywebapp.sock
    9 changes: 9 additions & 0 deletions mywebapp.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    from flask import Flask
    app = Flask(__name__)

    @app.route('/')
    def hello_world():
    return 'Hello World!'

    if __name__ == '__main__':
    app.run()
    12 changes: 12 additions & 0 deletions req.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    #!/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
    24 changes: 24 additions & 0 deletions setup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/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