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
    • 最新
    • 标签
主页 / user-546470

user2586441's questions

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
user2586441
Asked: 2019-12-05 14:08:13 +0800 CST

Windows Server 2012 使用默认网关,通过 openvpn 接口忽略更具体的路由

  • 1

Windows 2012 Server 有两个网络接口。一个具有静态 IPv4 配置和一个 TAP 适配器,该适配器在此服务器连接到远程 OpenVPN 服务器时被激活。

此服务器用于与 Internet 通信的物理 NIC 具有通常的 IPv4 设置(地址、掩码、默认网关、dns)。

与远程 OpenVPN 服务器建立连接后,IP 地址10.0.10.6/24通过 TAP 接口上的 DHCP 分配,我可以与 OpenVPN 的 ip 10.0.10.1通信。

但是,如果我尝试向 OpenVPN 服务器后面的网络添加路由,Windows 会忽略它——tracert 显示到该网络中主机的数据包通过默认网关。

这是已建立 VPN 连接的路由表。

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination      Netmask        Gateway       Interface  Metric
0.0.0.0           0.0.0.0          100.100.67.1   100.100.67.45    11
10.0.10.0         255.255.255.0    10.0.10.5      10.0.10.6        20
100.100.67.0      255.255.255.192  On-link        100.100.67.45   266
100.100.67.45     255.255.255.255  On-link        100.100.67.45   266
100.100.67.63     255.255.255.255  On-link        100.100.67.45   266
127.0.0.0         255.0.0.0        On-link        127.0.0.1       306
127.0.0.1         255.255.255.255  On-link        127.0.0.1       306  
127.255.255.255   255.255.255.255  On-link        127.0.0.1       306  
192.168.151.0     255.255.255.0    10.0.10.1      10.0.10.6        21
224.0.0.0         240.0.0.0        On-link        127.0.0.1       306  
224.0.0.0         240.0.0.0        On-link        10.0.10.6       276
224.0.0.0         240.0.0.0        On-link        100.100.67.45   266
255.255.255.255   255.255.255.255  On-link        127.0.0.1       306  
255.255.255.255   255.255.255.255  On-link        10.0.10.6       276
255.255.255.255   255.255.255.255  On-link        100.100.67.45   266
===========================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
          0.0.0.0          0.0.0.0  100.100.67.1  Default
===========================================================================

(我将 ISP 网络的前两个八位字节更改为 100.100)

此服务器 (10.0.10.6) 和 OpenVPN 服务器 (10.0.10.1) 之间的通信工作正常。如您所见,有一条通过 10.0.10.1 网关到 192.168.151.0/24 网络的路由,该网关可通过本地地址 10.0.10.6 获得

我像这样添加这条路线:

route add 192.168.151.0 mask 255.255.255.0 10.0.10.1

但是,在 192.168.151.0/24 网络中跟踪主机显示数据包通过默认路由发送到 Internet Provider,而不是通过网关 10.0.10.1 路由

C:\Users\user1>tracert -d 192.168.151.1
Tracing route to 192.168.151.1 over a maximum of 30 hops

  1    2 ms    2 ms    5 ms  100.100.67.1
  2   <1 ms   <1 ms    2 ms  213.239.245.229
  3    3 ms    5 ms    2 ms  213.239.224.13
^C
C:\Users\user1>

我错过了什么?

windows-server-2012-r2
  • 1 个回答
  • 403 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