AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[custom-errors](server)

Martin Hope
Sander Böhm
Asked: 2021-03-30 04:22:03 +0800 CST

自定义错误页面 apache

  • 2

我正在尝试设置自定义错误页面(反向代理是 apache)

Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

**Additionally, a 503 Service Unavailable error was encountered while trying to use an ErrorDocument to handle the request.**

但是,例如,如果我停止我的 tomcat 服务器,则不会加载错误页面(503 错误)

我收到上面的消息不是我的 .HTML 消息

我的配置如下所示:

<VirtualHost *:443>
ServerAdmin XXX
ServerName  XXX


# Possible values: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
ErrorLog XXX
CustomLog XXX
DocumentRoot /var/www/html/
ErrorDocument 503 /503.html

<Directory />
    AllowOverride None
    Require all granted
</Directory>

ProxyPreserveHost On
<Location />
    AddDefaultCharset Off
    Require all granted
    ProxyPass ajp://XXX:XXX/ disablereuse=on
</Location>

如果我将 ErrorDocument 行更改为 foo 而不是 /503.html 我会看到 foo 所以看起来 .HTML 不是由配置加载的?有人可以帮助我吗?

tomcat apache-2.4 custom-errors
  • 1 个回答
  • 432 Views
Martin Hope
user2586441
Asked: 2020-05-07 05:42:49 +0800 CST

带有嵌套代理的 Nginx 自定义 502 页面

  • 0

我知道如何为上游错误创建自定义 502 页面,并且多次没有问题,但是在这种特殊情况下,一个代理响应被传递给另一个代理,我找不到正确的配置。

一般的工作流程是这样的:用户请求图片的缩略图,nginx 将此请求代理到图片存储。如果 storage 返回 404,则 nginx 将此请求代理到应用服务器,应用服务器生成带有请求 URI 的缩略图并返回代码 200,通过 nginx 传递给用户。

但是,如果用户请求完全不存在图片的缩略图,则应用服务器返回 502。在这种情况下,我想显示一个自定义页面,而不是内置的 nginx“502 Bad Gateway”。

正如我在开始时提到的,我知道如何创建自定义 502 页面,但我认为这种具有双重代理的特殊复杂设置需要一些我找不到的额外配置 :( 我尝试了一个带有内部选项的位置,我我尝试了一个带有指向 html 页面的直接 URL 的位置,我尝试了“@”位置,但 nginx 总是显示其内置页面。文件 502.html 和 502x.html 都存在于 /var/www/html 中并且是可读的通过 nginx:

ll /var/www/html
total 20
drwxr-xr-x 2 root root 4096 May  3 11:21 ./
drwxr-xr-x 4 root root 4096 Mar 24 11:50 ../
-rw-r--r-- 1 root root   36 Apr 28 10:49 502.html
-rw-r--r-- 1 root root   36 May  3 11:21 502x.html

Nginx 配置:

server {
listen 443 ssl http2;
server_name cdn.domain.tld;

ssl_certificate /etc/letsencrypt/live/cdn.domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/cdn.domain.tld/privkey.pem;

client_max_body_size 10m;

client_body_buffer_size 128k;
proxy_connect_timeout 75;
proxy_send_timeout 300;
proxy_read_timeout 500;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_http_version 1.1;
proxy_buffering on;
proxy_redirect off;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

#locations for redirection of 502 response received from thumbnail generator. Not working :(
#error_page 502  @502;
#error_page 502  https://cdn.domain.tld/502x.html;
error_page 502  /502.html;
location =/502.html {
   root /var/www/html;
   internal;
}
location @502 {
   root /var/www/html;
   try_files /502x.html 502;
}
location = /502x.html {
   root /var/www/html;
   index 502x.html;
}

location  / {
    proxy_pass http://192.168.10.5/thumbs$request_uri;

    #Sets caching time for different response codes. If only caching time is specified  then only 200, 301, and 302 responses are cached.
    proxy_cache_valid 30m;

    add_header X-Proxy-Thumbs-Cache $upstream_cache_status;

    #intercept 404 from backend
    #from nginx docs:
    #If an error response is processed by a proxied server or a FastCGI/uwsgi/SCGI/gRPC server,.
    #and the server may return different response codes (e.g., 200, 302, 401 or 404), it is possible to respond with the code it returns (equal sign does that)
    #So we proxy 404 to app which generates thumbnail and returns it with 200 code
    proxy_intercept_errors on;
    error_page 404 = @not-found;

    access_log /var/log/nginx/cdn.access.log cachelog;
    error_log /var/log/nginx/cdn.error.log;
}

location @not-found {
   proxy_pass http://192.168.10.12/thumbgen?key=$request_uri;

   add_header X-Proxy-Thumbs-Cache2 $upstream_cache_status;

   proxy_intercept_errors on;

   access_log /var/log/nginx/cdn-404.access.log cachelog;
   error_log /var/log/nginx/cdn-404.error.log;
}

}

nginx 502-error custom-errors
  • 1 个回答
  • 560 Views
Martin Hope
lkp111138
Asked: 2017-02-14 07:41:12 +0800 CST

每个部分的默认字符集,包括错误页面

  • 0

我想故意为我服务器上的某些页面生成 404 错误,我目前正在处理标题。问题是,对于存在的脚本(并且我在脚本中给出了 404 错误),Content-Type标题字段显示text/html; charset=UTF-8,而对于真正的 404 页面,相同的字段显示text/html; charset=iso-8859-1,这违背了我的目的。我尝试添加AddDefaultCharset UTF-8到主配置,但没有运气。问题是,如何在这些真正的错误页面上设置字符集?

charset apache-2.4 custom-errors
  • 1 个回答
  • 377 Views
Martin Hope
Bob Ortiz
Asked: 2016-06-25 04:55:05 +0800 CST

当访问所有其他文件被拒绝时,如何将所有 HTTP 错误代码动态发送到一个 PHP 文件?

  • 1

我有以下情况,我正在开发一个 API。我将所有流量重写为一个名为: 的 PHP 脚本route.php,使用mod_rewrite如下:

1: RewriteEngine On
2: RewriteCond %{REQUEST_FILENAME} -f [OR]
3: RewriteCond %{REQUEST_FILENAME} -d
4: RewriteRule ^.* route.php [L]

其他文件不应该被访问,这就是为什么我route.php只使用白名单来访问。因此我使用这个:

order allow,deny
<FilesMatch "route\.php">
    allow from all
</FilesMatch>

我想将所有 1xx、2xx(200 除外)、4xx 和 5xx HTTP 状态代码发送到 PHP 脚本(假设error.php?code=404显示该状态代码的动态错误页面。在这种情况下,我可能必须允许访问error.php也在FilesMatch部分。

我找到了部分我想要的东西,如本文所述,但我无法实现或设法让它按照我上面描述的方式工作。

我的目的是error.php显示一个 JSON 输出(基于状态码动态),{'statusCode':'404','status':'Not Found'}包括我使用的所有常见(安全)HTTP 标头。

.htaccess web-applications mod-rewrite custom-errors errordocument
  • 1 个回答
  • 1797 Views
Martin Hope
petRUShka
Asked: 2012-07-04 09:55:02 +0800 CST

Apache:如何设置自定义 401 错误页面并保存原始行为

  • 4

我使用 Apache/2.2.3 (Linux/SUSE) 进行基于 Kerberos 的身份验证。当用户试图打开一些 url 时,浏览器会像 HTTP Basic Auth 一样询问域登录名和密码。如果用户取消此类请求 3 次,Apache 将返回401 Authorization Required错误页面。我当前的虚拟主机配置是

    <Directory /home/user/www/current/public/>
            Options -MultiViews +FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all
            AuthType Kerberos
            AuthName "Domain login"
            KrbAuthRealms DOMAIN.COM
            KrbMethodK5Passwd On
            Krb5KeyTab /etc/httpd/httpd.keytab
            require valid-user
    </Directory>

我想为用户设置漂亮的自定义 401 错误页面和一些说明。我在虚拟主机配置中添加了这样一行:

 ErrorDocument 401 /pages/401

它有效,当用户无法授权 apache 将他重定向到我的漂亮页面时。但是 Apache 不像以前那样询问用户登录\密码。我同时想要这个功能和漂亮的错误页面!

是否有可能使其正常工作?

apache-2.2 httpd kerberos custom-errors http-error-401.2
  • 2 个回答
  • 9281 Views
Martin Hope
Tobias
Asked: 2012-06-27 04:00:19 +0800 CST

如何为重定向的 Zope 创建 Apache 错误页面

  • 0

我有一些虚拟主机重定向到 Zope 服务器进程:

RewriteRule ^/(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/theroot/VirtualHostRoot/$1 [L,P]

当然,如果 Zope 进程没有运行,重定向就会失败。这可能发生在实例重启期间(例如更新),或者对于不应一直运行的开发/测试实例。在这种情况下,我想有一个友好的消息。

因此,为了错误处理的唯一目的,我定义了一个 DocumentRoot:

DocumentRoot /var/zope-instances/my-instance/htdocs
ErrorDocument 500 /error-500.html
ErrorDocument 503 /error-500.html

不幸的是,它不起作用;在 Zope 关闭时尝试访问页面时,Apache 告诉我:

由于维护停机或容量问题,服务器暂时无法为您的请求提供服务。请稍后再试。

此外,在尝试使用 ErrorDocument 处理请求时遇到了 503 Service Temporarily Unavailable 错误。

错误文档是世界可读的;目录是世界可执行的。

我该怎么做才能让错误页面运行?由于 mod_rewrite,有什么特别需要考虑的吗?

apache-2.2 custom-errors 500-error errordocument zope
  • 1 个回答
  • 1071 Views
Martin Hope
GrZeCh
Asked: 2010-03-23 06:02:49 +0800 CST

覆盖来自 .NET Framework 的 <customErrors mode="Off"/> 消息,即使在 web.config 中打开了详细错误

  • 1

这是否可以覆盖 .NET Framework 错误:

Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

...

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

即使 web.config (IIS7.5) 设置为

<httpErrors errorMode="Detailed"/>

? 我问是因为我对 IIS7 的默认设置是

<deployment retail="true" />

所以没有显示错误,只有向网站添加额外的错误处理模块才能看到此应用程序生成的错误,这就是为什么我要覆盖此消息以通知用户。

有任何想法吗?

谢谢

iis-7.5 custom-errors
  • 1 个回答
  • 4967 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve