Skip to content

Commit f9678c1

Browse files
committed
+ changed after codereview
1 parent 3e41def commit f9678c1

File tree

4 files changed

+82
-26
lines changed

4 files changed

+82
-26
lines changed

02_django_api/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:latest
2+
3+
ENV PYTHONUNBUFFERED 1
4+
5+
RUN mkdir /02-django-api
6+
WORKDIR /02-django-api
7+
COPY requirements.txt /02-django-api/
8+
RUN pip install --upgrade pip && pip install -r requirements.txt
9+
ADD ./02-django-api
10+
11+
EXPOSE 8000
12+
13+
CMD [ "python", "./manage.py runserver localhost:8000" ]

02_django_api/docker-compose.yml

+8-10
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,25 @@ services:
1313

1414

1515
django:
16-
build: ./02_movies_admin
17-
command: python manage.py runserver localhost:8000
16+
build: ./02_django_api
1817
depends_on:
1918
- db
20-
ports:
21-
- 8000:8000
2219
env_file:
2320
-./config/.env
2421
volumes:
25-
- static:/02_movies_admin/static
26-
- media:/02_movies_admin/media
27-
- nginx_conf:/02_movies_admin/nginx/
22+
- static:/02_django_api/static
23+
- media:/02_django_api/media
24+
- nginx_conf:/02_django_api/nginx/
2825

2926
nginx:
3027
image: nginx:latest
3128
ports:
3229
- "80:80"
3330
volumes:
34-
- static:/02_movies_admin/static
35-
- media:/02_movies_admin/media
36-
- nginx_conf:/etc/nginx/conf.d/
31+
- static:/02_django_api/static
32+
- media:/02_django_api/media
33+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
34+
- ./configs:/etc/nginx/conf.d:ro
3735
depends_on:
3836
- django
3937
restart: always

02_django_api/nginx.conf

+28-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
upstream djangodocker {
2-
server django:8000;
1+
worker_processes 1;
2+
3+
events {
4+
worker_connections 1024;
35
}
46

5-
server {
7+
http {
8+
include mime.types;
9+
include conf.d/*.conf;
610

7-
listen 80;
11+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
12+
'$status $body_bytes_sent "$http_referer" '
13+
'"$http_user_agent" "$http_x_forwarded_for"';
814

9-
location / {
10-
proxy_pass http://djangodocker;
11-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
12-
proxy_set_header Host $host;
13-
proxy_redirect off;
14-
}
15-
location /static/ {
16-
alias /02_movies_admin/static/;
17-
}
15+
sendfile on;
16+
tcp_nodelay on;
17+
tcp_nopush on;
18+
client_max_body_size 200m;
1819

19-
location /media/ {
20-
alias /02_movies_admin/media/;
21-
}
20+
gzip on;
21+
gzip_comp_level 3;
22+
gzip_min_length 1000;
23+
gzip_types
24+
text/plain
25+
text/css
26+
application/json
27+
application/x-javascript
28+
text/xml
29+
text/javascript;
2230

31+
proxy_redirect off;
32+
proxy_set_header Host $host;
33+
proxy_set_header X-Real-IP $remote_addr;
34+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
2335
}

02_django_api/site.conf

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
server {
2+
listen 80 default_server;
3+
listen [::]:80 default_server;
4+
server_name _;
5+
6+
root /data;
7+
8+
location @backend {
9+
proxy_pass http://django:8000;
10+
}
11+
12+
location ~ ^/(admin|api) {
13+
proxy_pass http://django;
14+
}
15+
16+
location /static/ {
17+
alias /02_django_api/static/;
18+
}
19+
20+
location /media/ {
21+
alias /02_django_api/media/;
22+
}
23+
24+
location / {
25+
try_files $uri $uri/ @backend;
26+
}
27+
28+
error_page 404 /404.html;
29+
error_page 500 502 503 504 /50x.html;
30+
location = /50x.html {
31+
root html;
32+
}
33+
}

0 commit comments

Comments
 (0)