Prohibit IP access to Web sites in a variety of ways to share (Linux,php,nginx,apache) _ Server Other

Source: Internet
Author: User
Tags iptables net domain

PHP prohibits access to an IP or IP segment

Don't say much nonsense, sir please see:

?  
Prohibit an IP
$banned _ip = Array (
"127.0.0.1",
//"119.6.20.66",
"192.168.1.4"
);
if (In_array getenv ("REMOTE_ADDR"), $banned _ip))
{
die ("Your IP is prohibited from accessing!") ");
}
Prohibit an IP segment
$ban _range_low=ip2long ("119.6.20.65");
$ban _range_up=ip2long ("119.6.20.67");
$ip =ip2long ($_server["REMOTE_ADDR"]);
if ($ip > $ban _range_low && $ip < $ban _range_up)
{
echo "Your IP is prohibited in the banned IP segment, access is forbidden!") ";
Exit ();
}


Apache prohibits using IP access

Method One: At the end of the httpd.conf file, add the following code

Namevirtualhost 221.*.*.*
<virtualhost 221.*.*.*>
ServerName 221.*.*.* <location/>
Order
Allow,deny
  Deny from all
</Location>
</VirtualHost>
<virtualhost 221.*.*.*>
DocumentRoot "C:/web"
ServerName www.jb51.net

Description: The blue part is to implement any access request that refuses to 221.*.*.* this IP directly, then if you use 221.*.*.* access, you will be prompted to deny access. The red section is to allow access through the Www.jb51.net domain name, and the home directory points to C:/web (assuming that your site's root directory is c:/web)

Linux Shielded IP Access

#屏蔽单个IP的命令是
iptables-i input-s 123.45.6.7-j DROP
#封整个段即从123.0.0.1 to 123.255.255.254 command
iptables-i INPUT- s 123.0.0.0/8-j drop
#封IP段即从123.45.0.1 to 123.45.255.254 command iptables-i input-s 124.45.0.0/16-j
Drop
# An IP segment is a command from 123.45.6.1 to 123.45.6.254 is
iptables-i input-s 123.45.6.0/24-j DROP
service iptables Save 


Save in/etc/sysconfig/iptables If no iptables files are created automatically

Nginx Prohibit IP access

The following configuration file is first established under Nginx's conf directory, named Blocksip.conf:

Deny 4.4.4.4//This is Nginx IP to be banned

Save it for a second.
In the Nginx configuration file nginx.conf, include blocksip.conf; Then restart the Nginx, and it will take effect. When the blocked IP opens the site, you will be prompted:

403 Forbidden

Blocksip.conf: There are a number of formats that can be configured to allow only IP access or IP segment access:

Deny IP;
Allow IP;
# Block all IPs
Deny all;
# Allow all IPs
Allow all;

The pattern of the network segment is this: 192.168.1.0/24 such a form.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.