question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It does not work on production server!

See original GitHub issue

Hello! I do like channels - it is good solution. I wrote a small application with channels - it works fine on localhost (without any problems).

Options:

  • Django 1.10
  • Linux Debian 8.5
  • Python 3.4

But problems arose when deploying: In my settings.py

...
INSTALLED_APPS = [
    ...
    'channels',
    ...
]
...
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'asgi_redis.RedisChannelLayer',
        'CONFIG': {'hosts': [('localhost', 6379), ], },
        'ROUTING': 'basic.channels.routing',
    },
}
...

I will repeat - it works fine on localhost!!! For deploy i create asgi.py:

import os
from channels.asgi import get_channel_layer

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'basic.settings')
application = get_channel_layer()

Previously, I run gunicorn used wsgi.py, but now I stopped gunicorn and run daphne: $ daphne -b 0.0.0.0 -p 3355 basic.asgi:application and workers: $ ./manage.py runworker

The site runs and works fine! But the page with socket has an error: WebSocket connection to 'ws://example.com/some/path/' failed: Unexpected response code: 200

I do not know - how to solve this problem? Please, show me your settings, and method that you run the Django project!

P.p.s Redis work too, I use redis for session and for page view count (port/host are correct).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
andrewgodwincommented, Jan 29, 2017

You must run two processes in production (runserver combines these for you normally):

  • daphne -b 0.0.0.0 -p 8001 yourproject.asgi:channel_layer - The webserver that receives connections. Point Nginx to this. More docs here: https://github.com/django/daphne
  • manage.py runworker - The Django worker. You can run as many of these as you like; they connect to Daphne via the channel layer.

You also need to not be using the in-memory channel layer.

3reactions
bastbnlcommented, Jan 29, 2017

Have you started the workers as well? You start them via manage.py runworker

Read more comments on GitHub >

github_iconTop Results From Across the Web

Production Server Issue: How to Solve It the RIGHT WAY
1. Finding the Root Cause vs. Implementing a Workaround. Imagine you spent two days finding the cause of the issue. · 2. Keeping...
Read more >
Site not working on production server - MSDN - Microsoft
my web site ascentmarketing.info/index.aspx work just fine on my test server but on my production Server Error asking me to add <customErrors mode="Off"/> ......
Read more >
Resolving a Production Issue on a Live Server
Steps Towards Resolving a Production Issue. Notify All Stakeholders: The first step is to communicate that the server is down to all ...
Read more >
HttpPost not working on production server - java
I have a back-end application build with Java which at some point needs to post some files in base64 format towards another server....
Read more >
Express Tutorial Part 7: Deploying to production
That makes deployment quite easy because you just need to concentrate on your web application and not any other server infrastructure. Some developers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found