nginx自定义错误页面
2019-12-15     loonlog     3399     0
本文目录
前几天,对频繁访问本站的ip进行黑名单设置,同时前端返回403禁止访问页面,默认页面为nginx自带页面,感觉不好看,也就是没有逼格;再者ip进入黑名单主要是为了恶意访问或者攻击,希望能对其进行告诫!当然也可能有误伤的时候,需要定制错误页面。
配置nginx.conf过程也比较简单:
1、在http内部增加:fastcgi_intercept_errors on;
2、在server内部的location内部增加页面配置,具体如下(省略号省略部分代码)
http {
...
fastcgi_intercept_errors on;
server {
...
location / {
....
include uwsgi_params;
uwsgi_pass 127.0.0.1:9110; #端口要和uwsgi里配置的一样
uwsgi_param UWSGI_SCRIPT web_pj.wsgi; #wsgi.py所在的目录名+.wsgi
uwsgi_param UWSGI_CHDIR /data/www/; #项目路径
#以上四行代码为django配置uwsgi代码
#下面是定义错误页面代码
error_page 403 /403.html;
error_page 500 502 503 504 /500.html;
location = /403.html {
root /usr/local/nginx/html;
allow all;
}
location = /500.html {
root /usr/local/nginx/html;
}
}
...
}
...
}
注意:
root /usr/local/nginx/html;是html文件所处路径,
403页面配置里面增加allow all;因为我这里设置了ip黑名单,deny语句把所有对403.html的访问都给给deny了,所以需要在locaction = /403.html 的语句里面加上allow all,那么我们是需要被禁ip对象也能访问这个错误页面,因此用到了allow all。
3、在上面路径中 /usr/local/nginx/html增加自己相应的html页面模板即可,重启nginx,即可。
评论列表,共 0 条评论
暂无评论