zoukankan      html  css  js  c++  java
  • Nginx配置自定义的403页面

    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;
    }
  • 相关阅读:
    php中rsa加密及解密和签名及验签
    php中ssl开发的若干问题
    手机web下拉加载
    SVN:One or more files are in a conflicted state
    phpstorm安装laravel-ide-helper实现自动完成、代码提示和跟踪
    Jquery AJAX POST与GET之间的区别
    $.ajax() ,$.post(),$.get() 的用法
    PHP XML和数组互相转换
    [2017-10-25]Abp系列——集成消息队列功能(基于Rebus.Rabbitmq)
    [2017-10-26]Abp系列——DTO入参验证使用方法及经验分享
  • 原文地址:https://www.cnblogs.com/peteremperor/p/11139416.html
Copyright © 2011-2022 走看看