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:
In this profile I then setup the appropriate folder containing the python script, callable entry function and uwsgi file:
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:
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
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
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.
It seems like you should pick your
*.py
file in this fieldI do not have the full answer, but I was able to make it work.
Here is my setup.
At the Web Station application:
At my router:
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.
My Python code at main.py (same as OP) is:
A few limitations:
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