# IP-FD.net for nginx: refuse addresses your IP-FD.net account rules block. # Needs nginx built with ngx_http_auth_request_module (most packages are). # # 1. Put the proxy_cache_path line in the http { } block. # 2. Put the "location = /_ipfd" block in your server { } block, with your API key. # 3. Add "auth_request /_ipfd;" to every location you want to protect. # # The check answers HTTP 200 (allow) or 403 (block). If IP-FD.net cannot be reached the request is let through. proxy_cache_path /var/cache/nginx/ipfd levels=1:2 keys_zone=ipfd:5m max_size=20m inactive=10m use_temp_path=off; # --- inside server { } --------------------------------------------------------------------------- location = /_ipfd { internal; proxy_pass https://ip-fd.net/api/v1/check/$remote_addr?status=1; proxy_ssl_server_name on; proxy_set_header Host ip-fd.net; proxy_set_header X-API-Key "YOUR_API_KEY"; proxy_pass_request_body off; proxy_set_header Content-Length ""; proxy_connect_timeout 1s; proxy_read_timeout 1s; # Remember the answer for 5 minutes per address proxy_cache ipfd; proxy_cache_key $remote_addr; proxy_cache_valid 200 403 5m; # Fail open: when IP-FD.net is down or slow, answer 200 for the check proxy_intercept_errors on; error_page 401 429 500 502 503 504 = @ipfd_allow; } location @ipfd_allow { internal; return 200; } # Example: protect the login page # location /login { # auth_request /_ipfd; # error_page 403 = @ipfd_denied; # proxy_pass http://backend; # } # # location @ipfd_denied { # default_type text/plain; # return 403 "Access denied"; # }