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
![Image[1]-Pagoda Panel WordPress Blog Blocking Mainland IP - Photon Flux | Professional WordPress Repair Service, Global Coverage, Fast Response](https://www.361sale.com/wp-content/uploads/2024/04/2024-04-22_10-56-04.png)
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
![Image[2]-Pagoda Panel WordPress Blog Blocking Mainland IP - Photon Flux | Professional WordPress Repair Service, Global Coverage, Fast Response](https://www.361sale.com/wp-content/uploads/2024/04/2024-04-22_11-01-46.png)
# Define a blacklist of IP address segments to be blockedgeo $block_cn {default 0;# IP address segment blocking range (pointing to uploaded IP data file)include /www/wwwroot/ipdata.txt;}# 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; }# 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.
![Image[3]-Pagoda Panel WordPress Blog Blocking Mainland IP - Photon Flux | Professional WordPress Repair Service, Global Coverage, Fast Response](https://www.361sale.com/wp-content/uploads/2024/04/2024-04-22_11-07-08.png)
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 at the back.
![Image[4]-Pagoda Panel WordPress Blog Blocking Mainland IP - Photon Flux | Professional WordPress Repair Service, Global Coverage, Fast Response](https://www.361sale.com/wp-content/uploads/2024/04/2024-04-22_11-13-20.png)
Open Settings and add a code to block mainland IPs:
![Image[5]-Pagoda Panel WordPress Blog Blocking Mainland IP - Photon Flux | Professional WordPress Repair Service, Global Coverage, Fast Response](https://www.361sale.com/wp-content/uploads/2024/04/2024-04-22_11-14-53.png)
if ($block_cn) {return 403; # block mainland IP access, return 403 forbidden}if ($block_cn) { return 403; # block mainland IP access, return 403 forbidden }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.
Link to this article:https://www.361sale.com/en/8604
The article is copyrighted and must be reproduced with attribution.
No comments