我正在使用django-websocket-redis来设置websocket。还使用nginx和docker。我遵循用法中提到的内容,尝试从客户端访问服务器时出错。
这是我的nginx.conf
location /api {
include /etc/nginx/uwsgi_params;
uwsgi_param HTTP_HOST {{ 'DOMAIN_NAME' | env }};
uwsgi_pass uwsgi://{{ upstream }};
uwsgi_read_timeout 600;
}
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
include /etc/nginx/uwsgi_params;
uwsgi_param HTTP_HOST {{ 'DOMAIN_NAME' | env }};
uwsgi_pass unix:///tmp/app_ws.sock;
}
这是我的uwsgi:
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = $(SRC)/
# Django's wsgi file
module = config.wsgi
# the virtualenv (full path)
# home = $(DEPLOY_ROOT)/app/
# process-related settings
# master
master = true
# set up app load optimizations
workers = 4 # maximum number of workers
cheaper = 2 # minimum number of workers at all times
cheaper-initial = 2 # num. of workers spawned at startup
cheaper-step = 1 # num. of workers spawned when algo decides more are needed
cheaper-algo = spare # (spare2) faster spawning, slower disposing
cheaper-busyness-verbose = true
# align header size with ELB
buffer-size = 16384
# use network socket
socket = :xxxx
# clear environment on exit
vacuum = true
# reload django app on file change (debug only)
if-env = PYTHON_AUTORELOAD
python-autoreload = %(_)
end-if =
pythonpath = $(SRC)/
base = $(SRC)/
这是我的websocket uwsgi:
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = $(SRC)/
# Django's wsgi file
module = config.wsgi_websocket
# the virtualenv (full path)
# home = $(DEPLOY_ROOT)/app/
http-websockets = true
gevent = 1000
# process-related settings
# master
master = true
# set up app load optimizations
workers = 4 # maximum number of workers
cheap = 2 # minimum number of workers at all times
cheaper-initial = 2 # num. of workers spawned at startup
cheaper-step = 1 # num. of workers spawned when algo decides more are needed
cheaper-algo = spare # (spare2) faster spawning, slower disposing
# align header size with ELB
buffer-size = 16384
# the socket (use the full path to be safe
socket = /tmp/app_ws.sock
# ... with appropriate permissions - may be needed
chmod-socket = 667
# clear environment on exit
vacuum = true
# reload django app on file change (debug only)
if-env = PYTHON_AUTORELOAD
python-autoreload = %(_)
end-if =
pythonpath = $(SRC)/
base = $(SRC)/
这是我遇到的错误。
app_1 | *** running gevent loop engine [addr:0x493be0] ***
app_1 | Python auto-reloader enabled
app_1 | Traceback (most recent call last):
app_1 | Traceback (most recent call last):
app_1 | File "gevent.libev.corecext.pyx", line 490, in gevent.libev.corecext.loop.io (src/gevent/libev/gevent.corecext.c:6698)
app_1 | File "gevent.libev.corecext.pyx", line 490, in gevent.libev.corecext.loop.io (src/gevent/libev/gevent.corecext.c:6698)
app_1 | File "gevent.libev.corecext.pyx", line 850, in gevent.libev.corecext.io.__init__ (src/gevent/libev/gevent.corecext.c:11105)
app_1 | File "gevent.libev.corecext.pyx", line 850, in gevent.libev.corecext.io.__init__ (src/gevent/libev/gevent.corecext.c:11105)
app_1 | ValueError: fd must be non-negative: -1
app_1 | ValueError: fd must be non-negative: -1
在没有websocket的情况下,我的应用程序正常运行,这意味着我可以在/ api下访问url。