Skip to content

Commit f18f5fe

Browse files
committed
🚀 add Daphne to nginx to handle ws
1 parent 58cf3ae commit f18f5fe

File tree

8 files changed

+23
-29
lines changed

8 files changed

+23
-29
lines changed

Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ WORKDIR /usr/src/app/messages/
3131

3232
EXPOSE 8000
3333

34-
COPY entrypoint.sh .
35-
RUN chmod +x entrypoint.sh
36-
3734
USER app-user
3835

3936
CMD ["run.sh"]

docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ services:
44
build:
55
context: .
66
dockerfile: Dockerfile
7-
entrypoint: ./entrypoint.sh
7+
command: >
8+
sh -c "python manage.py wait_for_db &&
9+
python manage.py migrate &&
10+
python manage.py runserver 0.0.0.0:8000"
811
image: messages-web-image
912
container_name: messages-web-container
1013
ports:

proxy/Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
FROM nginxinc/nginx-unprivileged:1-alpine
22

33
COPY ./default.conf.tpl /etc/nginx/default.conf.tpl
4-
COPY ./uwsgi_params /etc/nginx/uwsgi_params
54
COPY ./run.sh /run.sh
65

7-
ENV LISTEN_PORT=8000
8-
ENV APP_HOST=web
9-
ENV APP_PORT=9000
10-
116
USER root
127

138
RUN mkdir -p /vol/static && \
149
chmod 755 /vol/static && \
1510
touch /etc/nginx/conf.d/default.conf && \
1611
chown nginx:nginx /etc/nginx/conf.d/default.conf && \
12+
chown nginx:nginx /etc/nginx/default.conf.tpl && \
1713
chmod +x /run.sh
1814

1915
VOLUME /vol/static

proxy/default.conf.tpl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1+
upstream server_ws {
2+
server web:8001;
3+
}
4+
15
server {
2-
listen ${LISTEN_PORT};
6+
listen 8000;
37
48
location /static {
59
alias /vol/static;
610
}
711

812
location / {
9-
uwsgi_pass ${APP_HOST}:${APP_PORT};
10-
include /etc/nginx/uwsgi_params;
11-
client_max_body_size 10M;
13+
proxy_pass http://server_ws;
14+
15+
proxy_http_version 1.1;
16+
proxy_set_header Upgrade $http_upgrade;
17+
proxy_set_header Connection "upgrade";
18+
19+
proxy_redirect off;
20+
proxy_set_header Host $host;
21+
proxy_set_header X-Real-IP $remote_addr;
22+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
23+
proxy_set_header X-Forwarded-Host $server_name;
1224
}
1325
}

proxy/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

3-
envsubst < /etc/nginx/default.conf.tpl > /etc/nginx/conf.d/default.conf
3+
cat /etc/nginx/default.conf.tpl > /etc/nginx/conf.d/default.conf
44
nginx -g 'daemon off;'

proxy/uwsgi_params

Lines changed: 0 additions & 13 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ toml==0.10.2
4444
Twisted==22.10.0
4545
txaio==22.2.1
4646
typing_extensions==4.4.0
47-
uWSGI==2.0.21
4847
virtualenv==20.16.6
4948
wrapt==1.14.1
5049
zope.interface==5.5.1

scripts/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ python manage.py wait_for_db
66
python manage.py collectstatic --noinput
77
python manage.py migrate
88

9-
uwsgi --socket :9000 --workers 4 --master --enable-threads --module messages.wsgi
9+
daphne -b 0.0.0.0 -p 8001 messages.asgi:application

0 commit comments

Comments
 (0)