How deploy Flask application on Webfaction?

前端 未结 2 1273
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 06:38

Anybody know how to deploy a simple Flask application on Webfaction? I know Webfaction support mod_wsgi and I read the guide on the Flask site but still I can\'t make my app wor

相关标签:
2条回答
  • 2021-01-31 06:52

    You need to set up a "Custom app (listening on port)" application. Make a note of the port that is assigned. Then in your Flask code, you need to put hardcode the port:

    if __name__ == __main__:
        app.run(host='0.0.0.0' port=XXXXXXX)
    

    Where you substitute XXXXXXX with the port that is randomly assigned to your custom app.

    Hope that helps.

    EDIT:

    Please use Raben's Answer, this way should not to be used in Production.

    0 讨论(0)
  • 2021-01-31 06:58

    I got it working with the following procedure:

    • create and app named 'myapp' of type mod_wsgi 3.3/Python 2.7. Webfaction will create the following folders:

      myapp
           |- apache2
           |- htdocs
      
    • Webfaction will also automatically create a simple script index.py in your htdocs directory. Check if the sample script work visiting the root of your newly created application (to do thin on Webfaction you need to "mount" the app on a website). If it's all OK modify the script deleting the content and adding:

      from myapp import app as application
      
    • In apache2/conf/httpd.conf add the follwing lines:

      WSGIPythonPath /home/username/webapps/myapp/htdocs/
      #If you do not specify the next directive the app *will* work but you will
      #see index.py in the path of all subdir
      WSGIScriptAlias / /home/username/webapps/myapp/htdocs/index.py
      
      
      <Directory /home/username/webapps/myapp/htdocs>
          AddHandler wsgi-script .py
          RewriteEngine on
          RewriteBase /
          WSGIScriptReloading On
      </Directory>
      
    • Restart apache2

    0 讨论(0)
提交回复
热议问题