python on nginx

  • Hello,


    I have install nginx on my OMV4 and normally.
    i have a python program create by flask(on Visual Basic) running on my windows apache, and want to move it to my OMV
    Many try and error, i can run flask on activate virtualenv only
    i find lot of document for wsgi config ,flask/nginx on debian etc....but finally not work. ;(


    it is probable running flask or python thougth Nginx on OMV and any easy way to do that? Thank you for help

  • Hi- yes there is! I happen to be doing this right now! I'm testing this on OMV4 on RPi, and will redo it on my "production" OMV: Odroid XU4, all running Armbian/Debian 9. What's your OMV architecture?


    There seems to be a couple of ways to do it: A new "location" on the "/etc/nginx/sites-available/openmediavault-webgui" or (what I'll be doing, to keep things cleaner) create another "site", with a different port number, in this directory and symbolically linking to the "/etc/nginx/sites-enabled" directory.


    I found this very helpful: https://code.luasoftware.com/t…wsgi-for-flask-on-ubuntu/


    I basically followed the full script, using "uwsgi" in Emperor mode too. My Flask app is a RESTful API feeding a MySQL database. All of it will be on the OMV box.


    I got the full stack working on a copy of Raspbian, now to OMV.


    Hope this helps.


    Peter

  • Hi Peter,


    Tks for your reply ,refer to your tutorial, i can run my flask under activating virtualenv and using python myapp.py
    uwsgi --socket 0.0.0.0:8080 --protocol=http -w wsgi:app, it also work.


    However, cannot run it by run by a service / on Ngnix.


    It return 502 Bad Gateway but
    display Active: active (running) on screen


    Not very understand what is the problem
    Still working hard to fix it out

  • Hi
    I got stuck on that too initially and spent a bit of time figuring it out. In the end, it's quite straightforward:


    The "-w run:app" is the same as "module=run:app" when you use the Vassal ini file in /etc/uwsgi/vassals/<app_name>.ini.


    So, the flask python app you've created will have a name eg; run.py. In this 'run.py' script, there should be a line that reads like: 'app = Flask(__name__)'.


    Running the 'uwsgi --socket 0.0.0.0:8080 --protocol=http -w run:app' will start uwsgi on the localhost, listening on Port 8080, running your Python application called 'run.py', referencing the 'app' line inside your application.


    This may help: http://manpages.ubuntu.com/man…an1/uwsgi_python27.1.html


    Looks like you're very close to getting it working.

  • I Fix it and work now.
    1.i have wrongly config sock name on nginx, it should same as wsig created and case sensitive
    2.the directory that running on nginx set to 777, i granted owner and group (775), it also not work, 777 work now.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!