Skip to content

Commit 6c20b37

Browse files
committed
[TM-30] Add nginx and configure docker-compose accordingly
1 parent 24d0ed8 commit 6c20b37

6 files changed

Lines changed: 73 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
venv/
22
.env
33
.dockerenv
4+
staticfiles/

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,29 @@ services:
1919
command: gunicorn task_manager.wsgi:application --bind 0.0.0.0:8000
2020
volumes:
2121
- .:/app
22+
- ./staticfiles:/app/staticfiles
2223
ports:
2324
- "8000:8000"
2425
env_file:
2526
- .dockerenv
2627
depends_on:
2728
- db
2829

30+
nginx:
31+
image: nginx:stable-alpine
32+
container_name: nginx-proxy
33+
restart: always
34+
ports:
35+
- '80:80'
36+
- '443:443'
37+
volumes:
38+
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
39+
- ./nginx/sites:/etc/nginx/conf.d:ro
40+
- ./staticfiles:/app/staticfiles:ro
41+
depends_on:
42+
- web
43+
44+
2945
volumes:
3046
mysql_data:
3147

nginx/nginx.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
user nginx;
2+
worker_processes auto;
3+
error_log /var/log/nginx/error.log warn;
4+
pid /var/run/nginx.pid;
5+
6+
events {
7+
worker_connections 1024;
8+
}
9+
10+
http {
11+
include /etc/nginx/mime.types;
12+
default_type application/octet-stream;
13+
14+
sendfile on;
15+
tcp_nopush on;
16+
tcp_nodelay on;
17+
keepalive_timeout 65;
18+
types_hash_max_size 2048;
19+
20+
include /etc/ngninx/conf.d/*.conf;
21+
22+
}
23+

nginx/sites/default.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
location /static/ {
6+
alias /app/staticfiles/;
7+
expires 7d;
8+
add_header Cache-Control "public";
9+
access_log off;
10+
}
11+
12+
location / {
13+
proxy_set_header Host $host;
14+
proxy_set_header X-Real-IP $remote_addr;
15+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16+
proxy_set_header X-Forwarded-Proto $scheme;
17+
18+
proxy_connect_timeout 10s;
19+
proxy_read_timeout 120s;
20+
proxy_send_timeout 120s;
21+
22+
proxy_pass http://web:8000;
23+
}
24+
25+
error_log /var/log/nginx/error.log;
26+
access_log /var/log/nginx/access.log;
27+
28+
}
29+
30+
31+
0 Bytes
Binary file not shown.

task_manager/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# SECURITY WARNING: don't run with debug turned on in production!
3434
DEBUG = os.getenv('DEBUG') == 'True'
3535

36-
ALLOWED_HOSTS = ['*']
36+
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]']
3737

3838

3939
# Application definition
@@ -133,6 +133,7 @@
133133
# Static files (CSS, JavaScript, Images)
134134
# https://docs.djangoproject.com/en/5.2/howto/static-files/
135135

136+
STATIC_ROOT = '/app/staticfiles'
136137
STATIC_URL = 'static/'
137138

138139
# Default primary key field type

0 commit comments

Comments
 (0)