diff --git a/nginx.conf b/nginx.conf index 7ec1362..aca3f0d 100644 --- a/nginx.conf +++ b/nginx.conf @@ -74,11 +74,30 @@ server { if ($http_user_agent ~* (GoogleBot|bingbot|YandexBot|mj12bot|Apache-HttpClient|Adsbot|Barkrowler|FacebookBot|dotbot|Bytespider|SemrushBot|AhrefsBot|Amazonbot|GPTBot) ) { return 403; } - + location /admin/links/ { + try_files $uri @django-admin-slow; + } # checks for static file, if not found proxy to app try_files $uri @django; } - location /admin/links/ { + location @django { + # Cache + proxy_cache_valid 200 301 302 401 403 404 1d; + proxy_cache_bypass $http_pragma $no_cache_method $no_cache_control $no_cache_session; + proxy_cache_revalidate on; + proxy_cache cache; + add_header X-Cache-Status $upstream_cache_status; + # Rate limit + limit_req zone=bots burst=2 nodelay; + limit_req zone=one burst=1000 nodelay; + limit_req_status 429; + # Proxy + proxy_set_header X-Forwarded-Proto $web_proxy_scheme; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://django_server; + } + location @django-admin-slow { # https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout proxy_connect_timeout 120s; proxy_send_timeout 120s; @@ -86,8 +105,6 @@ server { # https://nginx.org/en/docs/http/ngx_http_core_module.html#send_timeout send_timeout 120s; keepalive_timeout 120s; - } - location @django { # Cache proxy_cache_valid 200 301 302 401 403 404 1d; proxy_cache_bypass $http_pragma $no_cache_method $no_cache_control $no_cache_session;