[Flask] serious problems with deploying flask app to server

Brad Derstine brad at bizzartech.com
Wed Sep 9 15:18:18 CEST 2015


For your questions,

1.        The virtualhost entry uses the wsgi mod to spin up a subprocess
that serves the http request, no port is required since wsgi handles that.

2.       I think your wsgi file is still wrong.

 

That "from application import app as application" line is specific to the
file structure of websitemixer, it will need to be adjusted for your
environment.

 

Try this instead.

##### /var/www/ourproject/ourproject.wsgi
import sys
sys.path.append("/var/www/ourproject/")
from ourproject import app

 

Remember to restart apache any time you make changes too since it isn't
loading files dynamically like the built in python web server does. Keep an
eye on the error_log of apache too, it may point at any issues not easily
seen since your using Apache and not the dev server.

 

-Brad

 

From: tigernassau [mailto:tigernassau at gmail.com] 
Sent: Tuesday, September 8, 2015 6:01 PM
To: Brad Derstine <brad at bizzartech.com>
Cc: Matt Gushee <matt at gushee.net>; flask at python.org
Subject: Re: [Flask] serious problems with deploying flask app to server

 

thks for info - ours is only different in that we are not running in
virtualenv (so don't have the activate code )  and not using ssl (later on
our task list)

still getting apache page - here is our test setup:

questions:  
1) we understand apache virtual find by name but how does it know what port
Flask would run on ??
2) without virtualenv do we still need to activate flask somehow ??
  
#### /var/www/ourproject/ourproject.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    return '<h1>Hello</h1>'
#
# if __name__ == "__main__":
#     app.run(debug=True)


##### /var/www/ourproject/ourproject.wsgi
# wsgi file
import sys
sys.path.append("var/www/ourproject")
# import os
# os.chdir("/var/www/ourproject")
from application import app as application


###### /etc/apache2/sites-enabled/ourproject.conf
<VirtualHost *>
  ServerName ourproject.com
  ServerAlias www.ourproject.com <http://www.ourproject.com> 
  DocumentRoot /var/www/ourproject/
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  WSGIDaemonProcess ourproject user=www-data group=www-data processes=2
threads=5
  WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi
  WSGIPassAuthorization On

  <Directory /var/www/ourproject>
      WSGIProcessGroup ourproject
      WSGIApplicationGroup %{GLOBAL}
      Require all granted
  </Directory>
</VirtualHost>







On 09/08/2015 01:53 PM, Brad Derstine wrote:

I've been creating some cookie cutter cms installs of flask with Apache 2.4
and mod_wsgi and running multiple other sites on a server using virtual
environments and virtualhosts. So far so good! Below is what's currently
working for me. I'm happy to explain anything I'm using. You can view the
full repo with setup.sh script for how I'm deploying it at
https://github.com/bderstine/WebsiteMixer-App-Base 

 

I installed to /srv/websitemixer.com/ <http://websitemixer.com/>  and here
are the files I used. YMMV

 

I'm using Ubuntu 14.04 and whatever Python 2.7 the official repos think is
current.

 

 

/srv/websitemixer.com/api.wsgi <http://websitemixer.com/api.wsgi> 

================

#!/bin/python

activate_this = '/srv/websitemixer.com/venv/bin/activate_this.py'
<http://websitemixer.com/venv/bin/activate_this.py%27> 

execfile(activate_this, dict(__file__=activate_this))

 

import sys

sys.path.append('/srv/websitemixer.com <http://websitemixer.com> ')

 

from application import app as application

================

 

 

/etc/apache2/sites-enabled/websitemixer.com.conf

================

<VirtualHost *:80>

    ServerName websitemixer.com <http://websitemixer.com> 

    ServerAlias www.websitemixer.com <http://www.websitemixer.com> 

    DocumentRoot /var/www

 

    WSGIDaemonProcess apiwebsitemixer user=www-data group=www-data threads=5

    WSGIScriptAlias / /srv/websitemixer.com/api.wsgi
<http://websitemixer.com/api.wsgi> 

    WSGIPassAuthorization On

 

    <Directory /var/www>

        Order deny,allow

        Allow from all

    </Directory>

 

    <Directory /srv/websitemixer.com <http://websitemixer.com> >

        WSGIProcessGroup apiwebsitemixer

        WSGIApplicationGroup %{GLOBAL}

        WSGIScriptReloading On

        Order deny,allow

        Allow from all

 

        ExpiresActive On

        #ExpiresByType text/css   "now plus 7 days"

        ExpiresDefault "access plus 1 month"

 

        <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">

        Header set Cache-Control "max-age=1296000, public"

        </FilesMatch>

        Require all granted

    </Directory>

 

    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/websitemixer.com <http://websitemixer.com>
-access.log combined

    ErrorLog ${APACHE_LOG_DIR}/websitemixer.com <http://websitemixer.com>
-error.log

 

</VirtualHost>

================

 

 

On Sep 8, 2015, at 3:30 PM, tigernassau <tigernassau at gmail.com
<mailto:tigernassau at gmail.com> > wrote:

 

On 09/08/2015 11:56 AM, Matt Gushee wrote:

Hi, Tiger--

I used to run a Flask site with nginx & uwsgi; I can't recall any major
issues with deployment. That site is not currently up, but I'll see if I can
find the configs. Meanwhile, this is just to let you know that it *should*
work. IMHO.


hope you can post a working solution - we made progress by also looking at
Bottle docs and now don't have server errors but Flask app domain is
reverting to the Apache page and not running the flask app - that would
indicated a virtual host issue but a static html page shows up fine on this
domain - maybe a port issue ??  - maybe the Flask app not running ??   maybe
version conflicts (used latest Deb 8 for python (2.7x) , mod-wsgi and pip
install Flask).  After 4 days, have run out of ideas to try.  

I realize there are variables (Apache vs Nginx, Debian vs Ubuntu vs RedHat,
standalone vs virtual hosts) but should be easy enough to have working
examples of these most typical deployments) 

Flask was really great for developing our site - now if we can only get it
deployed (:   






--

Matt Gushee

 

On Sat, Sep 5, 2015 at 10:22 PM, tigernassau <tigernassau at gmail.com
<mailto:tigernassau at gmail.com> > wrote:

Not sure whether it's an issue with docs or even a bug in wsgi  - what
should be a 30 minute task is turning into 3 days!

Although deploying the simple flask hello world example to a standard server
should be a really basic task, good step by step docs are really lacking -
we couldn't find a single specific working example and many other people
reporting trouble on stackoverflow are dissed without solutions.  The
pocoo.org <http://pocoo.org/>  docs do not show a working complete example -
this is making using Flask really difficult to use compared to other
frameworks.  Can we turn this example into some good step by step docs.

we first tried nginx w/ uwsgi but this failed big time - somehow nginx is
caching the non-working nginx.conf with uwsgi and couldn't clear it or even
reset the server - so purged nginx and moved to Apache

while apache is working fine for serving several other static sites with
virtual hosts, the following flask app is failing on Apache - it's also
caching some process so even after removing the app conf file in
sites-enabled, we cannot restart the server - apparently some process is
running that we cannot find or kill and requiring the whole server to come
down.  something is seriously wrong here - not sure what the hell wsgi is
doing.

ourproject.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    return '<h1>Hello</h1>'
if __name__ == "__main__":
    app.run(debug=True, host='127.0.0.1',port='8040')

ourproject.wsgi
#  wsgi file
import os, sys
sys.path.insert(0,"var/www/ourproject")
from ourproject import app as application


# ourproject.conf
<VirtualHost *:80>
  ServerName ourproject.com <http://ourproject.com/> 
  ServerAlias www.ourproject.com <http://www.ourproject.com> 
  DocumentRoot /var/www/ourproject/
  ErrorLog /var/www/ourproject/logs/error.log
  CustomLog /var/www/ourproject/logs/access.log combined

  WSGIDaemonProcess ourproject user=www-data group=www-data threads=5
  WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi

  <Directory /var/www/ourproject>
      WSGIProcessGroup ourproject
      WSGIApplicationGroup %{GLOBAL}
      Order allow, deny
      Allow from all
  </Directory>

  Alias /static /var/www/ourproject/static
</VirtualHost>

** not sure what %{GLOBAL} should be

1,1           Top



-- 
Tiger Nassau, Inc.
www.tigernassau.com <http://www.tigernassau.com/> 

_______________________________________________
Flask mailing list
Flask at python.org <mailto:Flask at python.org> 
https://mail.python.org/mailman/listinfo/flask

 






_______________________________________________
Flask mailing list
Flask at python.org <mailto:Flask at python.org> 
https://mail.python.org/mailman/listinfo/flask






-- 
Tiger Nassau, Inc.
www.tigernassau.com <http://www.tigernassau.com/> 

_______________________________________________
Flask mailing list
 <mailto:Flask at python.org> Flask at python.org
 <https://mail.python.org/mailman/listinfo/flask>
https://mail.python.org/mailman/listinfo/flask

 






-- 
Tiger Nassau, Inc.
www.tigernassau.com <http://www.tigernassau.com> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20150909/04f5d1d1/attachment-0001.html>


More information about the Flask mailing list