This guide details how to block mainland China IPs using Nginx and Pagoda Panel to secure your cross-border e-commerce website and comply with regional website access policies. Learn how to set up IP blacklists and customize HTTP response status codes (e.g. 403 Forbidden) to prevent unwanted regional access to your website.
1, first of all, first in Nginx to add the mainland IP shielding code
Log in to the Pagoda panel, find the Software Store, select Settings behind Nginx, and tap the
Open Settings and select Configuration Modifications on the left side of the http
The following code is added to the block for blocking mainland IP addresses, as shown below
# Define a blacklist of IP address segments to be blocked
geo $block_cn {
default 0;
# IP address segment blocking range (pointing to uploaded IP data file)
include /www/wwwroot/ipdata.txt;
}
Note: include denotes a reference, followed by the address of the uploaded IP data file ( IPdata.txt file download link)
Download the ip data file in parentheses above, and upload ipdata.txt to the /www/wwwroot/ directory, which corresponds to the path written in the code.
2, add the blocking code in the website that needs to block the mainland IP.
Find the website that needs to block mainland IP in the Pagoda, click the setting behind it.
Open Settings and add a code to block mainland IPs:
if ($block_cn) {
return 403; # block mainland IP access, return 403 forbidden
}
Add the above code in the same place as I did, where 403 is the status code returned if access is not possible, you can write 403, 404, 502, etc.
So far, open your website to test, with a continental IP access to your website domain name, it will prompt 403 no right to access.