如果配置没有问题,就会输出:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
[b]仅允许内网ip[/b]
如何禁止所有外网ip,仅允许内网ip呢?
如下配置文件
location / {
# block one workstation
deny 192.168.1.1;
# allow anyone in 192.168.1.0/24
allow 192.168.1.0/24;
# drop rest of the world
deny all;
}
上面配置中禁止了192.168.1.1,允许其他内网网段,然后deny all禁止其他所有ip。
[b]格式化nginx的403页面[/b]
如何格式化nginx的403页面呢?
首先执行下面的命令:
cd /usr/local/nginx/html
vi error403.html
然后输入403的文件内容,例如:
<html>
<head><title>Error 403 - IP Address Blocked</title></head>
<body>
Your IP Address is blocked. If you this an error, please contact binghe with your IP at test@binghe.com
</body>
</html>
如果启用了SSI,可以在403中显示被封的客户端ip,如下:
Your IP Address is <!--#echo var="REMOTE_ADDR" --> blocked.
保存error403文件,然后打开nginx的配置文件vi nginx.conf,在server配置节内添加下面内容。
# redirect server error pages to the static page
error_page 403 /error403.html;
location = /error403.html {
root html;
}