skip to Main Content

I noticed that Synology’s native webstation which uses uwsgi framework, has recently added support for python script. I was wondering if someone can help me figure out a simple hello world example. I am unclear about what to put in the uwsgi file.
I followed the python-flask quickstart example on uwsgi documentation page:
uwsgi python-flask quickstart

On webstaion>service portal : I setup a virtual host with nginx listening on port 8080:
webstation virtual host profile

In this profile I then setup the appropriate folder containing the python script, callable entry function and uwsgi file:
enter image description here

The "main.py" python script residing in this folder is the example in the quickstart page:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "<span style='color:red'>I am app 1</span>"

I took the command-line parameters in that example and made the uwsgi.ini file and placed it in the same folder:

[uwsgi]
socket = 127.0.0.1:8080
wsgi-file = main.py 
callable = app 
processes = 4
threads = 2 
stats = 127.0.0.1:9191

In webstation’s script>python page : I setup a "python-flask profile" and added the required flask module:
enter image description here

enter image description here

I added this "python-flask profile" in the virtual host’s python profile to make sure all modules are accessible to the python script.

However, when I browse to port 8080 I get error code 500 on my browser;

Internal Server Error

enter image description here

I would greatly appreciate if someone could try this out on webstation to figure out the correct setup. It seems that webstation makes deploying python based web-apps quite easy so solving this issue would greatly benefit newbies like me who are looking for a quick and easy deployment method on their Synology NAS.

Thanks in advance!

4

Answers


  1. For flask, I had to start on 0.0.0.0 to ensure the app was accessible from the LAN/WAN. If started on 127.0.0.1 or localhost, only the computer itself could access the app. It may be a first hint, for you?
    I manage to made my app run and accessible from the web but I still have to start it manually (ssh > command line) so it closed every time I closed the synology user session. On this part you seems far ahead of me.

    Login or Signup to reply.
  2. It seems like you should pick your *.py file in this field

    Field

    Login or Signup to reply.
  3. I do not have the full answer, but I was able to make it work.
    Here is my setup.

    At the Web Station application:
    enter image description here
    enter image description here
    enter image description here
    enter image description here

    At my router:
    enter image description here

    What I can see on my web browser.
    Tested with and without VPN (to simulate being outside my local network).
    Works with HTTP and HTTPS.
    enter image description here

    My Python code at main.py (same as OP) is:

    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/')
    def index():
        return "<span style='color:green'>I am app 1</span>"
    
    if __name__ == '__main__':
        app.run()
    

    A few limitations:

    • I am not able to make it work with another port. For example, 8080
    • The "Hostname" must be set
    • Only work with ports 80/443
    • Clear your browser cache
    • I am not able to find the server log
    • If the code crashes, it needs to Disable and Enable the Virtual Host
    Login or Signup to reply.
  4. enter image description here

    as already pointed out from @Jeremie you have to enter here (or navigate with "Browse…") to your "main.py"
    ! Ensure, that you have seted up the Root-Path corectly and the "main.py" is exactly at that location!

    @ juanbretti: I get it also run without "Hostname"-Config so with only use a HTTP-Port and the same Hostname/IP as SynologyNAS

    BR

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search