1.開啟nginx的狀態碼,虛擬主機配置中加入下邊一段
location /nginx_status
{
stub_status on;
access_log off;
}
或着在nginx的http模塊加入:fastcgi_intercept_errors on;
2.在server模塊加入
根據需求來配置,
因為deny語句把所有對403.html的訪問給deny了,所以需要在locaction = /403.html里面加上allow all,讓所有的IP地址能訪問403.html具體過程如下
需求A:允許某個拒絕所有
location / {
allow 192.168.1.0/24;
deny all;
error_page 403 /403.html;
location /403.html {
allow all;
}
}
需求B:拒絕某個允許所有
location / {
deny 192.168.1.0/24;
alllow all;
error_page 403 /403.html;
location /403.html {
allow all;
}
}
3.編寫403頁面,並放入html下面
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<h1>403 Forbidden</h1>
<p>You don't have permission to access the URL on this server. Sorry for the inconvenience.<br/>
This is a our test website, please visit our official website <a href="http://www.localhost.com" title="Click View Site " ><font size="5">www.localhost.com</a>
</font><br/>
Thank you very much!</p>
URL: http://www.localhost.com
<br/>Date:
<script language="JavaScript" type="text/javascript">
var enabled = 0; today = new Date();
var date;
M=today.getMonth() + 1
D=today.getDate()
HH=today.getHours()
MM=today.getMinutes()
SS=today.getSeconds()
if (M<10)
{
M="0"+M
}
if (D<10)
{
D="0"+D
}
if (MM<10)
{
MM="0"+MM
}
if (HH<10)
{
HH="0"+HH
}
if (SS<10)
{
SS="0"+SS
}
date = (today.getFullYear()) + "/" + M + "/" + D + " " + HH+":"+MM+":"+SS +"";
document.write(date);
</script>
</html>
4.service nginx restart 重啟nginx服務器
5.如果沒有生效加上這么一段
location = /403.html {
root /html;
allow all;
}