Coder Social home page Coder Social logo

ar-ngxrealip's Introduction

ar-ngxrealip

Show Real IPs instead of ArvanCloud IPs in Nginx servers

Prerequisites

You need the Nginx installed (using official packages or binaries) with ngx_http_realip_module enabled.

Also you can check this with nginx -V command.

nginx -V 2>&1 | egrep --color -o 'http_realip_module'
nginx -V 2>&1 | egrep --color -o 'realip_module'

How To Use ?

Modify nginx configuration

Open your nginx.conf or vhost configuration file and add this line to your http, server or location block

include /etc/nginx/arvancloud;

be sure that, the path should be same as ARVANCLOUD_FILE_PATH variable in arvancloud-ip-whitelist-sync.sh

Fetch arvancloud ip addresses

Execute the arvancloud-ip-whitelist-sync.sh to refresh arvancloud ip addresses.

#!/bin/bash

ARVANCLOUD_FILE_PATH=/etc/nginx/arvancloud

echo "# Arvancloud" > $ARVANCLOUD_FILE_PATH;
echo "" >> $ARVANCLOUD_FILE_PATH;

echo "# - IPv4" >> $ARVANCLOUD_FILE_PATH;
for i in `curl https://www.arvancloud.com/fa/ips.txt`; do
    echo "set_real_ip_from $i;" >> $ARVANCLOUD_FILE_PATH;
done

echo "" >> $ARVANCLOUD_FILE_PATH;
echo "real_ip_header ar-real-ip;" >> $ARVANCLOUD_FILE_PATH;

# check configuration and reload nginx
nginx -t && systemctl reload nginx

Check Your Output

Your /etc/nginx/arvancloud file may look like as below

# Arvancloud

# - IPv4
set_real_ip_from 92.114.16.80/28;
set_real_ip_from 185.112.35.144/28;
.
.
# there are couple of lines here that they set the real ip trusted ips
.
.
set_real_ip_from 89.45.48.8/29;
set_real_ip_from 185.105.101.200/29;

real_ip_header ar-real-ip;

Crontab

Change the location of arvancloud-ip-whitelist-sync.sh anywhere you want and add cron job to fetch Arvancloud ip address changes. moretherefore nginx will be realoded when synchronization is completed.

# Auto sync ip addresses of Arvancloud and reload nginx
30 2 * * * /path-to/arvancloud-ip-whitelist-sync.sh >/dev/null 2>&1

ar-ngxrealip's People

Contributors

3aaber avatar cipherbullet avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.