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 にアクセスできます。