在与NGINX和Supervisor建立网络套接字后,如何连接网络套接字



我在wsgi应用程序旁边创建了一个Django通道。如果我运行,一切都很好:

daphne -b 0.0.0.0 -p 8001 myapp.asgi:application 

我可以连接到webocekt,但在我用nginx创建了supervisor后,我无法连接,也没有看到任何有用的日志可以解决这个问题。

当我检查主管状态时,它没有错误:

asgi:asgi0                       RUNNING   pid 23981, uptime 0:10:22
asgi:asgi1                       RUNNING   pid 23980, uptime 0:10:22
asgi:asgi2                       RUNNING   pid 23983, uptime 0:10:22
asgi:asgi3                       RUNNING   pid 23982, uptime 0:10:22

套接字最初是localhost:8001,我也允许UFW使用该端口,但它不起作用,所以我改为我的服务器IP。

主管

[fcgi-program:asgi]
# TCP socket used by Nginx backend upstream
socket=tcp://139.162.172.87:8001
# Directory where your site's project files are located
directory=/home/markkiraly/crumb_backend
# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=/home/markkiraly/crumb_backend/venv/bin/daphne --fd 0 --access-log - --proxy-headers crumb_backend.asgi:application
# Number of processes to startup, roughly the number of CPUs you have
numprocs=4
# Give each process a unique name so they can be told apart
process_name=asgi%(process_num)d
# Automatically start and recover processes
autostart=true
autorestart=true
# Choose where you want your log to go
stdout_logfile=/var/log/asgi.log
redirect_stderr=true

NGINX CONFIG

upstream channels-backend {
server 139.162.172.87:8001;
}
server {
listen 80;
server_name crumbliterature.com www.crumbliterature.com;
location /static/ {
root /home/markkiraly/crumb_backend/;
}
location /media/ {
root /home/markkiraly/crumb_backend/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
location /ws/ {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_pass http://channels-backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
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-Host $server_name;
}
}

我试着用各种可能的方式连接:

ws://139.162.172.87/ws/chat/1/
ws://139.162.172.87:8001/ws/chat/1/
ws://crumbliterature.com/ws/chat/1/
ws://crumbliterature.com:8001/ws/chat/1/

1(

如果NGINX和Django频道位于一台机器上,那么您可以更换

upstream channels-backend {
server 139.162.172.87:8001;
}

带有

upstream channels-backend {
server localhost:8001;
}

2(

我不知道Django Channels,但如果默认或选定的端口被另一个应用程序阻止,一些应用程序可以尝试不同的端口。可能是你的应用程序工作,但与另一个端口或被卡住,但不通知它。尝试检查哪个应用程序在8001上侦听(如果有人侦听(

相关内容

  • 没有找到相关文章

最新更新