deploy app django digitalocean

I think google translate (assuming that’s what you’re using) did a poor job here. That doesn’t translate back correctly, and so I can see where the meaning is lost.

Yes, you can use any name for the file. But you still need to use the right suffix - proxy_pass http://unix:/run/gunicorn.sock:/ws/;

(haha I use Deepl when I don’t understand a word or if I have to translate it)

I have configured my nginx like you and restarted my nginx, but I still don’t see any data :no_mouth:

server {
    listen 80;
    server_name *********;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /var/www/html;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    location /ws/ {
        proxy_pass http://unix:/run/gunicorn.sock:/ws/;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect off;
    }

}

is there a way to know where the problem comes from?

Logs (either on the server or in the browser’s console) are your best source of information.

The network tab in your browser’s developer tools will show you what’s being sent and received through the websocket.

Errors should generally be logged somewhere - I’m guessing uvicorn would have its own logs.

You may also wish to add some logging to your consumers to see when connections are being made and the data being transferred.

You may also need to include the same proxy_params in your ws location as you do in the base location. (Or, you may need to create a copy of that file, remove what you don’t need or shouldn’t have, and include that edited version in this section.)

Sorry, I didn’t quite understand what I was supposed to do

ah okay like this?

server {
    listen 80;
    server_name ***********;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/wahab/apporder/static/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    location /ws/ {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock:/ws/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect off;
    }
}
1 Like

@KenWhitesell after several attempts I could not find the problem, there is a sokcet but the data is empty :thinking:

I have this error I do not know if it is related @KenWhitesell

2022/11/15 16:43:17 [warn] 67469#67469: conflicting server name "******" on 0.0.0.0:80, ignored

I also noticed that since we’ve been adding things, now every time I reload the page, in my network a ws is created

ws/
websocket?url=aHR0cDovLzE2MS4zNS44My4xODIvbXlhcHAvY29tbWFuZGU%3D&nocache=*****
ws/
websocket?url=aHR0cDovLzE2MS4zNS44My4xODIvbXlhcHAvY29tbWFuZGU%3D&nocache=*******
ws/
websocket?url=aHR0cDovLzE2MS4zNS44My4xODIvbXlhcHAvY29tbWFuZGV3YWl0bG9hZA%3D%3D&nocache=*******
ws/
websocket?url=aHR0cDovLzE2MS4zNS44My4xODIvbXlhcHAvY29tbWFuZGU%3D&nocache=*****

That’s always going to happen. Every page refresh will reconnect the websocket.

precisely that means that it does not work well before no? but I still don’t see what the problem is, maybe a version problem?

I’m not quite following what you’re asking here.

It is expected and appropriate behavior for a full-page refresh to cause the websocket to reconnect. That’s why most applications using them work in an “SPA-type” application.

As far as the reasons as to why you’re not seeing data through your websocket, you’re going to need to track that down from start to end. You’ll need to look at those connections to see what data is being exchanged between the browser and the server. You’ll also need to examine logs on the server to verify everything is working on that end. You may also need to add logging functions in your consumer (and possibly other parts of your application) to see what is happening within gunicorn.

You might even want to set up a network packet capture (e.g. tcpdump, wireshark, etc) between your browser and server to see what’s passing across the network.

Bottom line is that if you’re still having a problem with your websocket at this point, you’re going to need to gather more detailed information to help identify the source of the problem.

Thank you very much for your help, but I have not yet managed to solve the problem, although I have checked all the logs, but I can not find anything.

@KenWhitesell I finally got this webcoket to work, but there is a filter problem, it works fine when we configured it locally.

Nov 17 09:45:11 django411: queryset = self.filter_queryset(self.get_queryset(**kwargs), **kwargs)
Nov 17 09:45:11 django411: File "/home/wahab/apporder/./myapp/consumers.py", line 14, in get_queryset
Nov 17 09:45:11 django411: return HubriseOrder.objects.filter(ascount=self.scope["user"]).exclude(
Nov 17 09:45:11 django411: AttributeError: type object 'HubriseOrder' has no attribute 'filter'

you are right, you really have to look at each log to find out where the problem comes from