08-28 nginx访问控制-deny_allow
< 返回列表时间: 2020-02-19来源:OSCHINA
【围观】麒麟芯片遭打压成绝版,华为亿元投入又砸向了哪里?>>>
vi www.2.com.conf server { listen 80; server_name www.2.com; root /data/wwwroot/www.2.com; access_log /tmp/2.log; deny all; location ^~ abc { echo "^~*"; } location = "/abc/1.html" { echo "="; } }
[root @localhost vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root @localhost vhost]# /usr/local/nginx/sbin/nginx -s reload
[root @localhost vhost]# curl -x127.0.0.1:80 www.2.com/alskjdhf -I
HTTP/1.1 403 Forbidden
Server: nginx/1.8.0
Date: Wed, 19 Feb 2020 08:14:47 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
限制ip
vi www.2.com.conf server { listen 80; server_name www.2.com; root /data/wwwroot/www.2.com; access_log /tmp/2.log; allow 127.0.0.1; deny all; location ^~ abc { echo "^~*"; } location = "/abc/1.html" { echo "="; } }
[root @localhost vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root @localhost vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@localhost vhost]# curl -x127.0.0.1:80 www.2.com/alskjdhf -I
HTTP/1.1 404 Not Found
Server: nginx/1.8.0
Date: Wed, 19 Feb 2020 08:20:32 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
[root@localhost vhost]# curl -x192.168.239.3:80 www.2.com/alskjdhf -I
HTTP/1.1 403 Forbidden
Server: nginx/1.8.0
Date: Wed, 19 Feb 2020 08:21:26 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
限制IP段
vi www.2.com.conf server { listen 80; server_name www.2.com; root /data/wwwroot/www.2.com; access_log /tmp/2.log; allow 127.0.0.1; allow 192.168.0.0/24; deny all; location ^~ abc { echo "^~*"; } location = "/abc/1.html" { echo "="; } }
实例2
vi.www.2.com.conf server { listen 80; server_name www.2.com; root /data/wwwroot/www.2.com; access_log /tmp/2.log; location ~ admin { allow 192.168.239.0/24; deny all; } location ^~ abc { echo "^~*"; } location = "/abc/1.html" { echo "="; } }
[root@localhost vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@localhost vhost]# vi www.2.com.conf
[root@localhost vhost]# curl -x192.168.239.3:80 www.2.com/alsk/admin/ -I
HTTP/1.1 404 Not Found
Server: nginx/1.8.0
Date: Wed, 19 Feb 2020 08:45:01 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
其他IP拒绝
[root@localhost vhost]# curl -x127.0.0.1:80 www.2.com/alsk/admin/ -I
HTTP/1.1 403 Forbidden
Server: nginx/1.8.0
Date: Wed, 19 Feb 2020 08:48:47 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
热门排行