简体   繁体   中英

deploy django channels on nginx

I don't know anything about nginx and how to configure it to run channels. My environment is django 2.x ubuntu 16 nginx daphne redis digitalocean I've tinkered around with my nginx config file for a weeks now unable to get my socket to connect.

nginx config

server {
  listen 80;
  server_name x.x.x.x;

  location = /favicon.ico { access_log off; log_not_found off; }

  location /static/ {
    alias /home/admin1/myproject/channels-examples/multichat/static/ ;
  }

  location / {
    include proxy_params;
    proxy_pass http://unix:/home/admin1/myproject/channels-examples/multichat/multichat.sock
  }
}

I will greatly appreciate any assistance.

You need to run your app through daphne (you can read more here: https://channels.readthedocs.io/en/latest/deploying.html ) and configure related nginx section for websockets connections:

location / {
    proxy_pass http://127.0.0.1:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
  }

I had similar issues on my un-managed VPS.

Check this repository that I created when i figured out what worked for me.

your static location:

location /static/ {
    alias /home/admin1/myproject/channels-examples/multichat/static/ ;
}

should look like this:

location /static {
    alias /home/admin1/myproject/channels-examples/multichat;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM