Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

How to Block a Website visitors from certain countries using Nginx GeoIP

by Cloudbooklet
5 years ago
in Google Cloud, Compute Engine
How To Block A Website Visitors From Certain Countries Using Nginx Geoip
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Prerequisites Your Compute Engine Instance running. For setting up Compute Engine, see the Setting up Compute Engine Instance. For installing Nginx and PHP, see how to install LEMP in Compute Engine Instance. Domain name is pointed to your virtual machine. Learn how to Set up Google Cloud DNS for your domain. Block using GeoIP With […]

ADVERTISEMENT

Prerequisites

  1. Your Compute Engine Instance running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance.
  3. For installing Nginx and PHP, see how to install LEMP in Compute Engine Instance.
  4. Domain name is pointed to your virtual machine. Learn how to Set up Google Cloud DNS for your domain.

Block using GeoIP

With Nginx, blocking people from certain countries can be accomplished using the GeoIP module.

First, you’ll need to make sure that you have the GeoIP database installed.

SSH to your server and install GeoIP

ADVERTISEMENT
sudo apt install libnginx-mod-http-geoip geoip-database libgeoip1

Once this is installed or pre-installed in your server you can proceed to the configuration.

You might also like

How To Setup Ssh Keys On Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

4 months ago
Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago

Edit your Nginx configuration for your website.

sudo nano /etc/nginx/sites-available/yourdomainname.com

Add the following code above the server block to block visitors from US country.

ADVERTISEMENT
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allow_visit {
default yes;
US no;
#You can add additional countries
}

You can also allow visitor from certain countries and block every other.

geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allow_visit {
default no;
US yes;
#You can add additional countries
}

Now add the following inside your server block before location block.

ADVERTISEMENT
if ($allow_visit = no) {
#You can also use custom page redirection or whatever you need
return 403;
}

With the above code if a visitor visits your website from US they will get 403 Forbidden error.

This setup is tested with Nginx version 1.14.*

ADVERTISEMENT

I hope this post helps you to block your website visitors from certain countries using GeoIP.

ADVERTISEMENT
Tags: Compute EngineGoogle Cloud PlatformNginx
ShareTweetSendShare
Cloudbooklet

Cloudbooklet

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago
How To Change Timezone On Ubuntu 22.04

How to Change Timezone on Ubuntu 22.04

1 year ago
How To Install Ansible On Ubuntu 22.04

How to Install Ansible on Ubuntu 22.04

1 year ago

Follow Us

Trending Articles

Ai Girl Generator

7 Best AI Girl Generators for Creating Realistic and Beautiful AI Girls

September 19, 2023

How to See all my Birthday Posts on Facebook

Amazon Prime Big Deal Days 2023: Best Deals

How to Block YouTube Ads on Android TV in 2023 (6 Easy Methods)

AI Annotation Jobs: Everything You Need to Know

Wondershare Virbo AI Video Creation with New Features

Popular Articles

Donne App

How to Use the Donne App: A Step-by-Step Guide for Fashion Lovers

August 28, 2023

How to Make an AI Cover Song with Singify: A Step-by-Step Guide

NordVPN AI Gets a Major Upgrade with Nordlabs AI Integration

Llama Code: How Meta AI LLM Can Help You Write Better Code

12 Best AI Interior Design Platforms for 2023 [Free and Paid]

How to Create a Personal AI Assistant with LocalGPT

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.