webserver - 使用 nginx 返回自定义 403 错误页面

标签 webserver nginx http-status-code-403 custom-error-pages

每当发生 403 错误时,我都会尝试在/temp/www/error403.html 中显示错误页面。

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

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

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,但我仍然遇到相同的问题

最佳答案

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

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

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/

看来我对错误页面的访问被阻止的想法是正确的。

关于webserver - 使用 nginx 返回自定义 403 错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3119108/

相关文章:

ubuntu - 如何映射 mylocal :2700 to mylocal:80?

css - 最后使用问号 (?) 在浏览器中访问 CSS

python - 如何在我的 Web 服务器上运行 Python 脚本?

http - 在 Web 应用程序中使用 nginx 服务器转到 Web 服务器

php - POST url 403 在 Codeigniter 3 中被禁止

ios - 向网络服务器发送数据

node.js - GAE 中 Node JS 项目中的 HTTP 413 请求实体太大

php - 使用 PHP、MySQL、nginx 同时运行多个 Dockerize 项目

http - http响应状态码402和403的区别

linux - 访问某些 index.php 或 index.html 时出现 Apache 403 错误,尽管每个 index.php 或 index.html 具有相似的权限