How to use IP2Proxy with Nginx

Malicious activities usually done via an anonymous proxy where the perpetrator’s identity was hidden from tracking. You can easily fall prey to the fraudsters unless with the right tools to detect a proxy. You need to a way to easily tell if a visitor is coming from a non-proxy traffic, an open proxy, VPN, TOR, a data center range or a residential ISP range.

In this article, we will guide you on how to install IP2Proxy on a Debian platform and configure it to work with Nginx. At the end of this tutorial, you should be able to block or restrict IP address from an anonymous proxy by using IP2Proxy Nginx module and IP2Proxy database.


This section teaches you on how to install the IP2Proxy Nginx module into Debian platform.

  1. Make sure you have installed all required packages for development.

    apt-get update && apt-get upgrade
    apt-get install build-essential dh-autoreconf unzip
  2. Create a working directory.
    mkdir ~/nginx-dev && cd ~/nginx-dev
  3. Download the latest Nginx source code from
  4. Decompress the package.
    tar xvfz nginx-*.tar.gz
  5. Download latest IP2Proxy C library.
  6. Decompress downloaded package and install it to your system.

    cd ip2proxy-c-master
    autoreconf -i -v --force
    make install
    cd ~/nginx-dev
  7. Download and decompress IP2Proxy Nginx module.

  8. Go to Nginx source codes and start compilation

    cd ~/nginx-dev/nginx-VERSION
    ./configure --add-module=ip2proxy-nginx-master
    make install

IP2Proxy Database Download

IP2Proxy offers 10 type of free LITE databases and commercial databases. The free database contains limited proxy information and updates monthly instead of daily in commercial edition.

  1. Create new directory for IP2Proxy database.
    mkdir /etc/ip2proxy
    cd /etc/ip2proxy
  2. Go to Sign up an account for login and password.
  3. Download and decompress the latest IP2Proxy LITE database.
  4. wget “”


You need to configure Nginx to use IP2Proxy module.

  1. Edit
  2. Add following lines under `http` context:

    http {
    ip2proxy on;
    ip2proxy_database /etc/ip2proxy/IP2PROXY-LITE-PX11.BIN;
    ip2proxy_reverse_proxy on;
    ip2proxy_access_type shared_memory;



    Syntax: ip2proxy on|off
    Default: off
    Context: http, server, location
    Description: Enable or disable IP2Proxy Nginx module.

    Syntax: ip2proxy_database path
    Default: none
    Context: http
    Description: The absolute path to IP2Proxy BIN database.

    Syntax: ip2proxy_access_type file_io|shared_memory|cache_memory
    Default: shared_memory
    Context: http
    Description: Set the method used for lookup.

    Syntax: ip2proxy_proxy_recursive on|off
    Default: off
    Context: http
    Description: Enable recursive search in the x-forwarded-for headers.


    The following variables will be made available in Nginx:

    You may block the proxy traffic in Nginx as below:

    if ( $ip2proxy_is_proxy = 'Y' ) {
        return 444;


Was this article helpful?

Related Articles