Replies: 2 comments 5 replies
-
I updated my nginx to use an ip address:port, and then updated my uwsgi to use http:port, and now I am getting a new error about "The client is using an unsupported version of the Socket.IO or Engine.IO protocols"
|
Beta Was this translation helpful? Give feedback.
-
The only thing I am seeing in logs is the following
application log, nginx, and uwsgi logs.... not sure how else to troubleshoot, not seeing the typical EIO4 in any requests, im assuming thats determined automatically somehow. |
Beta Was this translation helpful? Give feedback.
-
I have an existing single page resume application that working just fine in production using flask, python, uwsgi, and nginx. I wanted to implement chat functionality into the application, but have had nothing but trouble.
In an effort to simplify things I have created a UWSGI emperor, and vassals, one is intended to serve the main application, which it is doing, The other was to deal with the flask socket.io functionality, which depending on the configuration, i have tried many, is either returning 502 or 504 errors.
I have read over suggested documents, and like i said tried dozens and dozens of different configurations with nginx/uwsgi/app.py.
Current /etc/nginx/sites-available/nginx.conf
`# HTTP to HTTPS redirect for all domains
server {
listen 80;
server_name jimploof.com www.jimploof.com jamesploof.com www.jamesploof.com portfolio.jimploof.com;
}
server {
listen 443 ssl;
server_name jimploof.com www.jimploof.com portfolio.jimploof.com;
}
server {
listen 443 ssl;
server_name jamesploof.com;
location /socket.io/ {
proxy_pass http://unix:/var/www/socketio/socketio.sock;
#proxy_pass http://localhost:8888/socket.io/;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
location /socket/ {
include uwsgi_params;
uwsgi_pass unix:/var/www/socketio/socketio.sock;
uwsgi_param SCRIPT_NAME /socket;
uwsgi_modifier1 30;
}
}
error_log /var/log/nginx/websocket_error.log debug;
`
current socket uwsgi vassal
[uwsgi] module = app:app master = true processes = 1 socket = /var/www/socketio/socketio.sock chmod-socket = 666 vacuum = true die-on-term = true enable-threads = true single-interpreter = true chdir = /var/www/socketio virtualenv = /var/www/socketio/venv plugins = python3 uid = www-data gid = www-data buffer-size = 65535 log-master = true logto = /var/www/socketio/uwsgi.log http-websockets = true harakiri = 120 post-buffering = 65535 thunder-lock = true max-requests = 2000 worker-reload-mercy = 60 reload-mercy = 60
and finally app.py
`# /var/www/socketio/app.py
import eventlet
eventlet.monkey_patch()
import os
import logging
import sys
from flask import Flask, render_template, request, jsonify
from flask_socketio import SocketIO
Enhanced logging setup
logging.basicConfig(
filename='/var/www/socketio/socketio.log',
level=logging.DEBUG,
format='%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
)
Also log to stderr for uWSGI
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.DEBUG)
logging.getLogger().addHandler(handler)
app = Flask(name)
app.config['SECRET_KEY'] = 'dev'
app.config['DEBUG'] = True
socketio = SocketIO(
app,
async_mode='eventlet',
logger=True,
engineio_logger=True,
cors_allowed_origins="*"
)
@app.route('/socket.io/test')
def test_client():
app.logger.info(f'Test client accessed from {request.remote_addr}')
try:
return render_template('index.html')
except Exception as e:
app.logger.error(f'Error serving test client: {str(e)}')
return str(e), 500
Add a health check route
@app.route('/socket.io/health')
def health_check():
return jsonify({'status': 'healthy'})
@app.errorhandler(Exception)
def handle_error(e):
app.logger.error(f'Unhandled error: {str(e)}')
return str(e), 500
@socketio.on_error()
def error_handler(e):
app.logger.error(f'SocketIO error: {str(e)}')
@socketio.on('connect')
def handle_connect():
app.logger.info(f'Client connected: {request.sid} from {request.remote_addr}')
@socketio.on('disconnect')
def handle_disconnect():
app.logger.info(f'Client disconnected: {request.sid}')
@socketio.on('message')
def handle_message(data):
app.logger.info(f'Received message from {request.sid}: {data}')
try:
socketio.emit('response', {'data': f'Server received: {data}'})
except Exception as e:
app.logger.error(f'Error sending response: {str(e)}')
if name == 'main':
socketio.run(app)
`
if i can figure this out ill definitely be giving back to community and writing a tutorial, thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions