-
-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to setup Flask-SockeIO for Ubuntu + SSL + uWsgi + NGINX configured as load balancer #1401
Comments
It does not appear that you have SSL in your uWSGI processes, correct? Then this line:
should be:
You also seem to be mixing two different communication protocols between nginx and uWSGI. For the HTTP routes you are using |
Miguel Thanks for your reply. you suggest to move everything to proxy_pass. but I really dont know how to change this to proxy_pass, because uwsgi_berry is the load balancing of my guess is i need probably change this to
|
The Flask-SocketIO documentation shows working configurations for uWSGI and nginx. You can start from that and then adapt those configs to your needs one step at a time, making sure things continue to work with each small change you make: https://flask-socketio.readthedocs.io/en/latest/#uwsgi-web-server |
I saw this documentation, but
Miguel - I'm very sure as the developer of this amazing package that you already test it as long i dont have a sample code for that, i'll keep my trials and probably my next steps this is from the docs:""" upstream socketio_nodes {
} server { how to configure Load balancer ? is this possible?
} |
Unfortunately I don't have the time or the bandwidth to create documentation for projects other than my own. As I mentioned above, I provide minimal configuration examples that I have confirmed personally. It would be impossible for me to provide documentation for every possible way to configure nginx, uWSGI, etc.
As I said before, I do not know if you can use both the uwsgi and the http protocols in the same server instance. You'll have to experiment yourself with this, or ask on a uWSGI forum for assistance. I stand by my recommendation to switch everything to the http protocol, get everything to work, then start tweaking the configuration until you get what you want.
I don't. This isn't my project and I'm not very familiar with it. When I needed to test with uWSGI I found what I needed from Google searches. Stack overflow in particular answers many of these questions.
The syntax to load balance is the same for websocket and HTTP. The example in the docs shows how it is done for WebSocket, you can do the same for HTTP. If you intend to use the uwsgi protocol for your http and/or websocket traffic then you'll have to figure out how to do it yourself, I've always used the http protocol in my tests. |
Miguel, Thank you for taking the time to answer that. I'll follow your recommendation to use the http protocol for both the flask app itself and the websockets. Thanks again ! |
update: the steps to resolve that are:
last thing is to config NGINX as Load balancer with SSL listening to 443 its works ! |
Hello,
I spend the last 3 days on this, reading a lot of documentation (there is not a lot regarding uWsgi + ngix+ssl+ load balancer(nginx)), but still didnt able to configure my app to connect to the Flask-SocketIO
with a configuration of :
Flask App (2 apps, each has different port/uwsgi socket)
uWSGI services ( 2 services in systemd configured)
Nginx configured for Load Balance between these 2 apps.
the flask app with flask-SockectIO app.py :
from flask_socketio import SocketIO, Namespace, emit, join_room, leave_room, close_room, rooms, disconnect
..
..
socketio = SocketIO(app, logger=True, engineio_logger=True, debug=True, cors_allowed_origins = None)
..
running the app directly
(kjVirtualEnv) $ python app.py
works fine!
running using uWSGI directly with command line - works fine !
(kjVirtualEnv) $ uwsgi --socket 0.0.0.0:7024 --http-websockets --protocol=http -w wsgi:app
the app deployed twice for horizontal scaling:
/home/berry/projects/python/kjBerry1
/home/berry/projects/python/kjBerry2
(with 2 different uwsgi ini files, 2 sockects , 2 services in systemd , etc.. )
they both work just fine also with NGINX - its just the Flask-SocketIO i still CANT setup to work
the nginx configured to use SSL (self signed certificate, the http to https redirect works fine)
using NGINX i get error only for the Web Sockets -
the app is working, nginx serving pages from kjBerry1 or kjBerry2 with the LOAD BALANCER setup just fine (but not for web sockets)
the errror is:
[error] 53946#53946: *24 peer closed connection in SSL handshake while SSL handshaking to upstream
PLEASE any answer/help or link to a blog or stack overflow that i didnt find will be appreciated
THANKS !
+--------------------------------------------------------------------------------------+
| kjBerry1.service
+--------------------------------------------------------------------------------------+
[Unit]
Description=uWSGI instance to serve kjBerry1
After=network.target
[Service]
User=berry
Group=www-data
WorkingDirectory=/home/berry/projects/python/kjBerry1
Environment="PATH=/home/berry/projects/python/kjBerry1/kjBerry1Venv/bin"
ExecStart=/home/berry/projects/python/kjBerry1/kjBerry1Venv/bin/uwsgi --ini kjBerry1.ini
[Install]
WantedBy=multi-user.target
+--------------------------------------------------------------------------------------+
uwsgi ini file : kjBerry1.ini
[uwsgi]
module = wsgi:app
master = true
processes = 1
socket = kjBerry1.sock
chmod-socket = 660
http-websockets = true
gevent = 1000
vacuum = true
logto = /home/berry/projects/python/kjBerry1/uwsgi-berry.log
die-on-term = true
nginx:
The text was updated successfully, but these errors were encountered: