feat: tune nginx config

This commit is contained in:
Alessandro Pezzè 2021-03-23 19:11:33 +01:00
parent af8c80d422
commit 384e86ee47

View file

@ -1,7 +1,7 @@
worker_processes 4; # 80$ droplet, so 4 core enabled
worker_processes 2;
events {
worker_connections 8096; # accepted incoming connections*2
worker_connections 4096;
multi_accept on; # accept each connection as soon as you can
accept_mutex off;
use epoll;
@ -17,7 +17,7 @@ http {
client_body_buffer_size 10K; # raise the threshold by which requests are written to HDD instead of RAM
client_header_buffer_size 2k;
client_max_body_size 8m; # we dont accept requests larger that 8mb, probably you are DoSing us
client_max_body_size 8m; # we dont accept requests larger that 8mb
sendfile on;
tcp_nopush on;
@ -25,16 +25,18 @@ http {
keepalive_timeout 5;
gzip on; # enable zipping files
gzip_vary on;
gzip_min_length 5120; # enable it only for medium-big files (slowbro size is 7000)
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/json;
gzip on;
gzip_disable "msi6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml;
upstream pokeapi_upstream {
# 'app' is the Django container name in Docker
# DO NOT EDIT IT ALONE or it'll break docker-compose
server app:8000 fail_timeout=0;
}
@ -58,15 +60,13 @@ http {
server {
listen 80 deferred;
server_name _;
root /code;
include /ssl/ssl.conf*;
client_body_timeout 5s;
client_header_timeout 5s;
root /code;
# Admin console
location /graphql/admin/ {
expires 1m; # client-side caching, one minute for each API resource
@ -78,9 +78,7 @@ http {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://graphql_upstream/;
}
@ -102,51 +100,26 @@ http {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://graphql_upstream/v1/graphql;
}
location /media/ {
root /code;
autoindex off;
}
location /static/ {
alias /code/assets/;
autoindex off;
}
location /api/ {
expires 1m; # client-side caching, one minute for each API resource
add_header Cache-Control "public";
add_header Pragma public;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://pokeapi_upstream;
}
# location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { # cache all these extensions for 5 days, disable logging
# access_log off;
# log_not_found off;
# expires 5d;
# add_header Cache-Control "public";
# add_header Pragma public;
# }
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://pokeapi_upstream;
}
}