Skip to main content

Primary links

  • Home
  • AI
  • Kubernetes
  • Incus
  • Ansible
  • Terraform
  • OpenStack
  • Virtualization
  • Linux
  • SmartHome
  • HowTo

Misc

  • Linux
  • Hardware
  • Programming
    • Graphic
    • HTML / PHP / CMS
      • AJAX
      • Apache
      • CSS
      • Drupal
      • Flash video
      • HTML examples
      • PHP
      • WebDAV
      • Webserver UTF-8 encoding
      • framebreaker
      • nginx
        • Log client ip
        • Nginx access control / GeoIP
        • linux, nginx, webserver
    • Java
    • PL / SQL
    • Magento
    • python
    • Asterisk
    • C / C++
    • JavaScript
    • Json
    • Magento
    • OpenOffice / LibreOffice
    • Perl
    • Postfix
    • Regular Expression
    • TLA
    • Tomcat
    • Zenity
    • bash
    • find
    • git
    • ofbiz
    • wildfly
    • xml
  • Databases
  • Multimedia
  • Windows

Cloud

  • OpenStack
  • cloud-config
  • nextcloud

Virtualization

  • Virtualization
  • Incus
  • Docker
  • KVM
  • Kubernetes
  • LXC
  • LXD
  • QEMU
  • VMware
  • VirtualBox
  • multipass
  • podman
  • vagrant
  • XEN

Network

  • DNS
  • Firewall
  • Linux
  • OpenvSwitch
  • SSL
  • VLAN
  • VPN
  • iPXE
  • namespaces
  • nmcli
  • tcpdump

Storage

  • CEPH
  • DRBD
  • LVM
  • S3
  • ZFS
  • btrfs

Automation / CI/CD

  • Install
  • Ansible
  • GitLab
  • LLM
  • Preseed
  • Puppet
  • Terraform
  • Ubuntu autoinstall

Monitoring / Visualisation

  • Grafana
  • Icinga
  • Prometheus
  • Monitoring
  • ELK
  • mermaid
  • nginx
  • linux
cat < /etc/nginx/conf.d/geoip.conf 
geoip_country /usr/share/GeoIP/GeoIP.dat;

map $geoip_country_code $allowed_country {
    default no;
    DE yes;
    CH yes;
}

log_format allow "allow $remote_addr;";
EOF
chmod 644 /etc/nginx/conf.d/geoip.conf


cat < /usr/local/bin/nginx-allow
#!/bin/bash

while inotifywait --quiet --event create,delete --exclude "[^c][^o][^n][^f]$" /tmp
do
    /usr/sbin/nginx -t && /usr/sbin/service nginx reload
done
EOF
chmod 755 /usr/local/bin/nginx-allow


cat < /etc/systemd/system/nginx-allow.service
[Unit]
Description=Nginx configuration monitor service
After=nginx.service

[Service]
Type=simple
ExecStart=/usr/local/bin/nginx-allow
Restart=on-abort

[Install]
WantedBy=multi-user.target
EOF
chmod 644 /etc/systemd/system/nginx-allow.service


systemctl daemon-reload
systemctl enable nginx-allow.service 
systemctl start nginx-allow.service 



cat < /etc/cron.hourly/clean_nginx_allow
#!/bin/bash

find /tmp -ctime +2 -name nginx_allow_*.conf -delete
EOF


cat /etc/nginx/sites-available/nginx-allow
...
set $backend $scheme://10.0.10.101;
error_page 403 =404 /404.gif;

location /nginx-allow/ {
    if ($allowed_country = yes) {
        access_log /tmp/nginx_allow_$remote_addr.conf allow;
        proxy_pass $backend;
    }

    proxy_pass $backend/404.html;
}

location ~ ^(/wp-admin|/admin) {
    include /tmp/nginx_allow_*.conf;
    deny all;

    proxy_pass $backend;
}
...

cat < /root/bin/nginx_allow_ddns.sh
#!/bin/bash -e

DDNS=foo.dyndns.com

sleep 3

IP=$(getent hosts ${DDNS} | cut -d" " -f1)
[ -n ${IP} ] && echo "allow ${IP};" > /tmp/nginx_allow_${IP}.conf

service nginx reload
EOF

# crontab -e
@reboot /root/bin/nginx_allow_ddns.sh

Links
https://docs.nginx.com/nginx/admin-guide/mail-proxy/mail-proxy/
https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-by-geoip/
https://www.justinsilver.com/technology/linux/nginx-configuration-monitor/
https://guides.wp-bullet.com/auto-whitelist-dynamic-dns-address-nginx-security/
https://mensfeld.pl/2014/08/nginx-block-access-to-certain-parts-of-your-app-based-on-visitor-country/
http://www.mylinuxtips.info/linuxtipstutorials/webservers/how-to-block-countries-on-nginx-with-geoip-module/
https://www.digitalocean.com/community/tutorials/how-to-use-nginx-s-map-module-on-ubuntu-16-04

Profiles GitHub StackOverflow LinkedIn Xing
Contact Imprint
© panticz 2026

Cookie-Einstellungen

Diese Website nutzt eingebettete Inhalte von Drittanbietern (z.B. YouTube, SoundCloud). Beim Laden dieser Inhalte werden Daten an die jeweiligen Anbieter übermittelt. Datenverarbeitungserklärung