使用Nginx返回自定义403错误页面 [英] Return custom 403 error page with nginx

查看:1432
本文介绍了使用Nginx返回自定义403错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论何时发生403错误,我都试图在/temp/www/error403.html中显示错误页面.

Im trying to display the error page in /temp/www/error403.html whenever a 403 error occurs.

这应该是每当用户尝试通过https(ssl)访问站点且其IP在blovkips.conf文件中时,但此刻仍显示nginx的默认错误页面. 我的其他服务器具有相同的代码(没有任何阻止),并且可以正常工作.

This should be whenever a user tries to access the site via https (ssl) and it's IP is in the blovkips.conf file, but at the moment it still shows nginx's default error page. I have the same code for my other server (without any blocking) and it works.

是否阻止IP访问自定义403页面? 如果是这样,我如何使它工作?

Is it blocking the IP from accessing the custom 403 page? If so how do I get it to work?

server  {
    # ssl
    listen               443;
    ssl                  on;
    ssl_certificate      /etc/nginx/ssl/site.in.crt;
    ssl_certificate_key  /etc/nginx/ssl/site.in.key;
    keepalive_timeout    70;

    server_name localhost;


    location / {
            root   /temp/www;
            index  index.html index.htm;
}

# redirect server error pages to the static page
error_page   403  /error403.html;
# location = /error403.html {
#         root   /temp/www;
# }

    # add trailing slash if missing
    if (-f $document_root/$host$uri) {
            rewrite ^(.*[^/])$ $1/ permanent;
    }      

    # list of IPs to block
    include blockips.conf;
}

将error_page代码从504更正为403,但是我仍然遇到相同的问题

Corrected error_page code from 504 to 403 but I still have the same issue

推荐答案

在来到这里之前,我做了很多谷歌搜索,但现在又做了一些,在5分钟内我得到了答案:P

I did heaps of googling before coming here but did some more just now, within 5 minutes I had my answer :P

似乎我不是唯一遇到此问题的人:

Seems I'm not the only person to have this issue:

error_page 403 /e403.html;
  location = /e403.html {
  root   html;
  allow all;
}

http://www. cyberciti.biz/faq/unix-linux-nginx-custom-error-403-page-configuration/

似乎我以为我对错误页面的访问已被阻止是正确的.

Seems that I was right in thinking that access to my error page was getting blocked.

这篇关于使用Nginx返回自定义403错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆