{"id":16162066,"url":"https://github.com/peterdavehello/nginx-cdn-set-real-ip","last_synced_at":"2025-07-17T14:04:44.010Z","repository":{"id":70808171,"uuid":"219496394","full_name":"PeterDaveHello/nginx-cdn-set-real-ip","owner":"PeterDaveHello","description":"Help nginx recognize clients' real IP, instead of Cloudflare/Fastly IP when using their CDN 🌐","archived":false,"fork":false,"pushed_at":"2023-06-03T15:22:16.000Z","size":13,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T19:40:09.665Z","etag":null,"topics":["address","cdn","client","cloudflare","fastly","hacktoberfest","ip","nginx","real-ip","server","web"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PeterDaveHello.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"PeterDaveHello","open_collective":"peterdavehello","ko_fi":"peterdavehello","liberapay":"PeterDaveHello","issuehunt":"peterdavehello"}},"created_at":"2019-11-04T12:28:06.000Z","updated_at":"2024-08-12T19:54:32.000Z","dependencies_parsed_at":"2024-10-21T14:37:39.740Z","dependency_job_id":null,"html_url":"https://github.com/PeterDaveHello/nginx-cdn-set-real-ip","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PeterDaveHello/nginx-cdn-set-real-ip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterDaveHello%2Fnginx-cdn-set-real-ip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterDaveHello%2Fnginx-cdn-set-real-ip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterDaveHello%2Fnginx-cdn-set-real-ip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterDaveHello%2Fnginx-cdn-set-real-ip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PeterDaveHello","download_url":"https://codeload.github.com/PeterDaveHello/nginx-cdn-set-real-ip/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterDaveHello%2Fnginx-cdn-set-real-ip/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265614003,"owners_count":23798364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["address","cdn","client","cloudflare","fastly","hacktoberfest","ip","nginx","real-ip","server","web"],"created_at":"2024-10-10T02:28:58.712Z","updated_at":"2025-07-17T14:04:43.986Z","avatar_url":"https://github.com/PeterDaveHello.png","language":"Shell","funding_links":["https://github.com/sponsors/PeterDaveHello","https://opencollective.com/peterdavehello","https://ko-fi.com/peterdavehello","https://liberapay.com/PeterDaveHello","https://issuehunt.io/r/peterdavehello"],"categories":[],"sub_categories":[],"readme":"# nginx-cdn-set-real-ip\n\nThis script generates an nginx configuration file that sets the correct client IP address based on CDN's IP addresses and the corresponding header.\n\n## Supported CDN\n\n- Cloudflare (`cf`, using header `CF-Connecting-IP`)\n- Fastly (`fastly`, using header `Fastly-Client-IP`)\n\n## Installation\n\nYou can either clone this repository to your server, or download the script directly from the repository:\n\n```sh\n# Clone the repository\ngit clone https://github.com/PeterDaveHello/nginx-cdn-set-real-ip /opt/nginx-cdn-set-real-ip\n\n# OR download the script directly\nmkdir -p /opt/nginx-cdn-set-real-ip/\ncurl -sLo /opt/nginx-cdn-set-real-ip/generate.sh https://raw.githubusercontent.com/PeterDaveHello/nginx-cdn-set-real-ip/master/generate.sh\n```\n\n\u003e Note: The `/opt` directory may require root privileges to write to. If you encounter permission errors, you may need to run the above commands with `sudo`.\n\n## Usage\n\nTo execute the script, ensure correct permissions and include supported CDN codes separated by a space if multiple CDNs are needed:\n\n```sh\n./generate.sh \u003cCDN\u003e [[CDN] [CDN]]\n```\n\nFor example:\n\n```sh\n$ sudo /opt/nginx-cdn-set-real-ip/generate.sh cf\nStart nginx real client ip config generation...\n\nConfig target: /etc/nginx/conf.d/cloudflare-set-real-ip.conf\n\nFetching Cloudflare IP addresses...\nGenerating nginx configuration file...\nNginx configuration for Cloudflare IP addresses added successfully.\n```\n\n### Cronjob\n\nThe script supports a `--cron` argument that causes it to randomly pause for 0-900 seconds before executing, in order to prevent sending too many requests to the CDN from the same region and avoid excessive updates occurring simultaneously.\n\nYou can add a cronjob with supported CDN to trigger the IP update script periodically and reload nginx for the new config.\n\nFor example, create `/etc/cron.d/opt/nginx-cdn-set-real-ip` with the following contents:\n\n```cron\n1 1 * * * root /opt/nginx-cdn-set-real-ip/generate.sh fastly --cron \u0026\u0026 /usr/sbin/service nginx reload\n```\n\nThis will run the script every day at 01:01 AM and reload nginx with the new configuration.\n\n## How it Works\n\nThe script fetches the latest CDN IP addresses from official sources and generates an nginx configuration file in `/etc/nginx/conf.d/cdn-set-real-ip.conf`.\n\nIt uses the `set_real_ip_from` directive to specify the trusted CDN IP addresses and the `real_ip_header` directive to set the corresponding header as the source of the real IP address.\n\nIf there are no changes to the CDN IP addresses, the script will exit without updating the configuration file.\n\n## Reference\n\n### Cloudflare\n\n- \u003chttps://www.cloudflare.com/ips/\u003e\n- \u003chttps://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers-\u003e\n\n### Fastly\n\n- \u003chttps://api.fastly.com/public-ip-list\u003e\n- \u003chttps://developer.fastly.com/reference/api/utils/public-ip-list/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterdavehello%2Fnginx-cdn-set-real-ip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterdavehello%2Fnginx-cdn-set-real-ip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterdavehello%2Fnginx-cdn-set-real-ip/lists"}