nginx 自定义403页面
1,在nginx的http模块加入:
1
|
fastcgi_intercept_errors on;
|
2,在server模块加入
根据需求来配置,
因为deny语句把所有对403.html的访问给deny了,所以需要在locaction = /403.html里面加上allow all,让所有的IP地址能访问403.html具体过程如下
需求A:允许某个拒绝所有
1
2
3
4
5
6
7
8
|
location / {
allow 192.168.1.0
/24
;
deny all;
error_page 403
/403
.html;
location
/403
.html {
allow all;
}
}
|
需求B:拒绝某个允许所有
1
2
3
4
5
6
7
8
|
location / {
deny 192.168.1.0
/24
;
alllow all;
error_page 403
/403
.html;
location
/403
.html {
allow all;
}
}
|
3,编写403页面,并放入html下面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# vim 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://monitor.10fei3.top/fzj/index.html"
title=
"Click View Site "
><font size=
"5"
> monitor.10fei3.
top
<
/a
>!
<
/font
><br/>
Thank you very much!<
/p
>
URL: http:
//monitor
.10fei3.
top
/
<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
>
<hr/>Powered by 10fei3.
top
!<
/body
>
<
/html
>
|
4.重新加载配置文件
1
|
# /etc/init.d/nginx reload
|
因本人知识有限,请大神们帮帮忙:
1,有没有大神知道淘宝的403页面怎么写啊,http://img.taobao.com/
2, 有没有大神知道京东的405页面怎么配置, http://img11.360buyimg.com/
希望大神能指点一下,不胜感激。
本文转自独弹古调 51CTO博客,原文链接:http://blog.51cto.com/hunkz/1840200,如需转载请自行联系原作者