Skip to content

Commit b916ad9

Browse files
committed
add nginx comperssion and caching
1 parent d426499 commit b916ad9

File tree

3 files changed

+91
-30
lines changed

3 files changed

+91
-30
lines changed

nginx/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
FROM nginx:alpine
22

3-
COPY nginx.conf /etc/nginx/conf.d/default.conf
3+
COPY default.conf /etc/nginx/conf.d/default.conf
4+
COPY nginx.conf /etc/nginx/nginx.conf

nginx/default.conf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
upstream collectorapp {
2+
server django:8000;
3+
}
4+
5+
server {
6+
listen 80;
7+
8+
location / {
9+
proxy_set_header Host $http_host;
10+
proxy_set_header X-Real-IP $remote_addr;
11+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
12+
proxy_set_header X-Forwarded-Proto $scheme;
13+
proxy_pass http://collectorapp;
14+
}
15+
16+
location /static/ {
17+
alias /usr/src/app/staticfiles/;
18+
expires 365d;
19+
}
20+
21+
location /ws/ {
22+
proxy_http_version 1.1;
23+
proxy_set_header Upgrade $http_upgrade;
24+
proxy_set_header Connection "upgrade";
25+
proxy_set_header X-Forwarded-Proto https;
26+
proxy_redirect off;
27+
proxy_set_header Host $host;
28+
proxy_set_header X-Real-IP $remote_addr;
29+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
30+
proxy_set_header X-Forwarded-Host $server_name;
31+
proxy_pass http://collectorapp;
32+
}
33+
}

nginx/nginx.conf

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,59 @@
1-
upstream collectorapp {
2-
server django:8000;
1+
user nginx;
2+
worker_processes auto;
3+
4+
error_log /var/log/nginx/error.log notice;
5+
pid /var/run/nginx.pid;
6+
7+
8+
events {
9+
worker_connections 1024;
310
}
411

5-
server {
6-
listen 80;
7-
8-
location / {
9-
proxy_set_header Host $http_host;
10-
proxy_set_header X-Real-IP $remote_addr;
11-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
12-
proxy_set_header X-Forwarded-Proto $scheme;
13-
proxy_pass http://collectorapp;
14-
}
15-
16-
location /static/ {
17-
alias /usr/src/app/staticfiles/;
18-
}
19-
20-
location /ws/ {
21-
proxy_http_version 1.1;
22-
proxy_set_header Upgrade $http_upgrade;
23-
proxy_set_header Connection "upgrade";
24-
proxy_set_header X-Forwarded-Proto https;
25-
proxy_redirect off;
26-
proxy_set_header Host $host;
27-
proxy_set_header X-Real-IP $remote_addr;
28-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29-
proxy_set_header X-Forwarded-Host $server_name;
30-
proxy_pass http://collectorapp;
31-
}
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /var/log/nginx/access.log main;
22+
23+
sendfile on;
24+
#tcp_nopush on;
25+
26+
keepalive_timeout 65;
27+
28+
gzip on;
29+
gzip_disable "msie6";
30+
31+
gzip_vary on;
32+
gzip_proxied any;
33+
gzip_comp_level 6;
34+
gzip_buffers 16 8k;
35+
gzip_http_version 1.1;
36+
gzip_min_length 256;
37+
gzip_types
38+
application/atom+xml
39+
application/geo+json
40+
application/javascript
41+
application/x-javascript
42+
application/json
43+
application/ld+json
44+
application/manifest+json
45+
application/rdf+xml
46+
application/rss+xml
47+
application/xhtml+xml
48+
application/xml
49+
font/eot
50+
font/otf
51+
font/ttf
52+
image/svg+xml
53+
text/css
54+
text/javascript
55+
text/plain
56+
text/xml;
57+
58+
include /etc/nginx/conf.d/*.conf;
3259
}

0 commit comments

Comments
 (0)