0

I have a Flask application that i am setting up under windows. In my httd.conf file, i include the conf file for my application, which resides in a directory like this:

C:\prod\apps\my_app\
                    \my_app
                        my_app.conf
                        my_app.py
                        my_app.wsgi
                    \my_service
                    \my_data
                    \my_python_virtual_env

I am able to configure this in Apache and get it running just fine using absolute paths for WSGIPythonPath in the my_app.conf. However, i can not getting it working using relative paths for WSGIPythonPath. I would assume, based on above structure, that it should be something like this:

WSGIPythonPath ../my_app;../my_service;../my_data;../my_python_virtual_env
<Directory "/">
    Require all granted
</Directory>

That clearly is not how apache is interpreting the root these relative paths however. Is what i'm tyring to do possible and if not, any other suggestions on how to get this to work? It would be great to have a single conf file for the various environments deployed to.

1 Answer 1

1

You need to read up more on how WSGI and modwsgi works with Apache and what the best practices are.

First, you should build your Flask application in an isolated virtualenv. This is a best practice for any Python-based web application, be it Flask, Django, whatever. Manage your packages with pip. Google those two terms and you will be greeted with multiple tutorials on how to do it.

Then, you should place your Flask app configuration in an Apache named virtual host on a dedicated port. You need to make sure your WSGIDaemonProcess includes your virtualenv specific python-path variable that points to the Flask site-packages.

You should also create a system Flask user and group to isolate the Flask system from everything else. This is much safer.

Listed below is a sample configuration. Note I have created a specific flask-main user and flask-main group, and I am pointing all traffic to my Flask app to port 8789.

#####
# START: Flask App
WSGISocketPrefix /var/run/wsgi
Listen 8789    
NameVirtualHost *:8789
<VirtualHost *:8789>
    DocumentRoot /path/to/www/
    ErrorLog "/path/to/logs/httpd/flask-8789-error_log"
    LogLevel info 
    ProxyRequests Off
    WSGIDaemonProcess flask-main user=flask-main group=flask-main display-name=%{GROUP} python-path=/path/to/www:/path/to/lib/python2.6/site-packages
    WSGIProcessGroup flask-main
    WSGIScriptAlias / /path/to/www/mygateway.wsgi process-group=flask-main application-group=%{GLOBAL}
    <Directory /path/to/www>
        WSGIProcessGroup run
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
    <Directory /path/to/www/static>                                                        
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

I hope that helps you to move in the right direction.

Sign up to request clarification or add additional context in comments.

2 Comments

I am on windows. Last i read, WSGIDaemonProcess was not valid option on windows. Pip is very problematic for us on windowsx64 with python2.7x64. it does not install some packages, such as pandas, as it requires a vc++ compiler. Works fine for 32bit pandas, but throws fits when using 64bit binaries. Lastly..is the answer that i can not use relative paths with WSGIPythonPath?
If all you are wondering is about relative paths in the WSGIPythonPath check the documentation. This is the same as setting a PYTHON_PATH env setting, so in my opinion it should be an absolute path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.