Q:

Remote access to virtualenv

I have apache httpd installed on server 10.37.45.89 which is having wsgi_module installed in it.I have placed my wsgi.conf file under /etc/apache2/conf.d location having details as following:
<virtualhost *:80>
    ServerName my.webtool

    WSGIDaemonProcess webtool user=www-data group=www-data threads=5 home=/home/user/flask-dev
    WSGIScriptAlias / /home/user/flask-dev/webtool.wsgi

    <directory /home/user/flask-dev>
        WSGIProcessGroup webtool
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        Order deny,allow
        Allow from all
    </directory>
</virtualhost>

I have Flask installed on another server  10.37.45.90 in which i have first set up virtualenv in following manner
(user@ajdfhklfhasjdf01 [~/flask-dev]) sudo pip install virtualenv
(user@ajdfhklfhasjdf01 [~/flask-dev]) sudo virtualenv venv
(user@ajdfhklfhasjdf01 [~/flask-dev]) source venv/bin/activate
(venv)(user@ajdfhklfhasjdf01 [~/flask-dev])
(venv)(user@ajdfhklfhasjdf01 [~/flask-dev]) sudo pip install Flask

I have following hierarchy of my code and wsgi file:
(venv)(user@ajdfhklfhasjdf01 [~/flask-dev])$ ls
__init__.py*  webtool.wsgi*

(venv)(user@ajdfhklfhasjdf01 [~/flask-dev])$ cat webtool.wsgi
import sys
sys.path.append('/home/user/flask-dev')
from webtool import app as application

(venv)(user@ajdfhklfhasjdf01 [~/flask-dev])$ cat __init__.py
import socket
from flask import Flask
app = Flask(__name__)
host_ip_address = socket.gethostbyname(socket.gethostname())
@app.route("/")
def hello():
    return "Hello world!"
if __name__ == "__main__":
    app.run(debug=True,host=host_ip_address,port=30004)

I am not sure as to how to perform linkage between these two servers so that Flask can serve request given by httpd. 

A:

I'm not an expert on this topic, but I think if you are running your python application on a different server, WSGI might be not possible / the wrong choice.
Instead: set your apache up to act as a reverse proxy
Run your flask app on the remote server using a "production-quality" WSGI server instead of flask's built-in werkzeug development WSGI server.
Popular choices are uWSGI, gunicorn, gevent, ...
I found waitress to be a good choice for that.
It comes with an command line tool, so you can start your app by issueing:
waitress-serve --port=8080 myapp:wsgifunc
Then have your apache proxy to http://:8080.

