[new] [Windows OS]

WS2k8r2: Multiple Flask-Web-Apps with same IP

How to make Flash apps work under Windows Server 2008 r2?

Flask, WSGI, mod_wsgi.so, Windows Server, IIS, internet information server, Apache, Python3.4.4, Apache2.4, httpd.conf, vhosts.conf, <Virtual Host>, WSGIScriptAlias, authentication, reversed proxy,

Sheity Solutions

Flask apps run under the builtin development server

1a Reversed Proxy in IIS

    • Principle: configure a web site as 'reverse proxy' in IIS ('url rewrite')
    • HTTP-requests to yourdomain.com are rerouted to localhost:5000
    • Application runs under builtin development server of Flask (http://localhost:5000/)
    • Example: http://old.pollr.ga
    • Problems: authentication (facebook, persona) fails, slow, not scalable

1b Different ports (Flask builtin server)

    • Principle: start flask development server with <ipnum>:<prtnum>
    • Flask: app.run(debug=False, host='69.969.696.96', port=8888)
    • Example: http://example.com:8888
    • Problems: authentication (facebook), web sites are expected under default port (*:80), not scalable

2 Configure IIS for WSGI

3 My solution: let Apache 2.4.18 serve WSGI-apps

3.1 Big Picture

  • All 64bit/VC10 binaries of mod_wsgi, Python3.4.4(64) and Apache2.4.x (64)
    • Note! VC10(64) == [MSC v.1600 64 bit (AMD64)]
  • Dedicated user under Windows server (WS2k8R2) runs Apache and Python
  • mod_wsgi.so makes Apache run Flask apps (wsgi)
  • Multiple flask applications are defined in Apache with the <VirtualHost *:80> directive
  • Flask app domains (eg: http://pollr.ga) point to the 'Apache-IP' (listen <IP>)

3.2 PRELIMINARIES

Let's assume we have disk S: (systems) and a disk W: (websites)

  1. With an RDT admin account create dedicated user.
    • User: wipyfla (groups: users, remote desktop users) (wipyfla == WsgIPYthonFLAsk)
  2. Create folders
    • Apache2418(64)-folder (s:/Apache241864 )
    • Python344(64)-folder (s:/Python34464 )
    • Data-folder (w:/sites/wipyfla )
  3. Security settings
    • Give user 'wipyfla' full control of these folders
  4. Create folders
    • Logs-folder: w:/sites/wipyfla/apachelogs
    • Apache-DocumentRoot-folder: w:/sites/wipyfla/root )

3.3 BASIC INSTALLATION

  1. Use RDT to login on server with user: wipyfla
  2. Download and Install Python3.4.4 (64,vc10) Windows
    • download from: https://www.python.org/downloads/
    • install in the planned folder (eg: s:/Python34464) with options below
    • install-option: only for our this user (wipyfla)
    • install-option: add to path
  3. Test Python-install
  4. Download (from https://www.apachelounge.com/download/VC10/) and Install Apache2.4.18 (64,vc10) Windows
    • Download
    • Unzip in the planned folder (eg: s:/Apache241864)
  5. Download and install MS Visual C 10 redistribute package

3.4 Basic Apache Configuration

3.5 Install modules and packages in Python

3.6 Install mod_wsgi.so in Apache

  • Download mod_wsgi-4.4.22+ap24vc10-cp34-none-win_amd64.whl from http://goo.gl/AtudWd-
  • Unpack mod_wsgi.so from the .WHL-file with 7Zip (mod_wsgi-4.4.22+ap24vc10.data/data/mod_wsgi.so)
  • Copy mod_wsgi.so to the modules-direcory of Apache
  • Add a line in http.conf under # Dynamic Shared Object (DSO) Support
    • Add as the last LoadModule-line:
    • LoadModule wsgi_module modules/mod_wsgi.so
  • See also: Version 2 in http://gutsup.com/oneletter/425/

3.7 Define virtual hosts in Apache for Flask apps

  • Create Virtual Hosts file in <Apache>/conf/extra
  • Filename: httpd-flask-vhosts.conf
  • Include conf/extra/httpd-flask-vhosts.conf in conf/httpd.conf

CONTENTS

3 Flask sites are now running, TRY IT!

3.8 Example of a Flask app

In conf/extra/httpd-flask-vhosts.conf:

...
ServerName hw.shareshit.nl
 WSGIScriptAlias / W:/sites/wipyfla/flask/helloworld/hwapplication.py
...

Contents of hwapplication.py

#hwapplication.wsgi
'''
 hello world app
'''
#
import sys, os
# W:\sites\wipyfla\flask\helloworld
sys.path.insert (0,r'W:\sites\wipyfla\flask\helloworld')
os.chdir('W:')
os.chdir(r'W:\sites\wipyfla\flask\helloworld')
from hw2 import app as application

Contents of hw2.py

# hw2.py (flask hello world)

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return '''Hello World (hw2.py) <br />!
Apache is serving a Flask app'''


#if __name__ == "__main__":
#    app.run(host='127.0.0.1', port=9191)

Links

Files (all VC10;

2016-01-27  15:54        26,054,656 python-3.4.4.amd64-vc10.msi   (PYTHON)
2015-12-02  17:54         5,673,816 vcredist_x64_vc10.exe (MSVC redistributable)
2016-01-28  13:13        13,305,855 httpd-2.4.18-win64-vc10.zip (APACHE)
2016-01-28  13:21            45,809 mod_wsgi-4.4.22+ap24vc10-cp34-none-win64.whl (MOD_WSGI.SO)

TIP =>Unpack the .whl with 7Zip => mod_wsgi.so

( by Tide to win developers at 2016-01-28 08:04:20 in Windows OS )



International money transfers? Worldremit beats your bank!

Domains, Hosting? Go Versio!

[Login to add a comment]
[new]