【问题标题】:Nginx - How do I proxy all 404 requests to a different serverNginx - 如何将所有 404 请求代理到不同的服务器
【发布时间】:2018-04-29 23:24:19
【问题描述】:

我正在尝试将我的所有 404 请求代理到备用服务器,也适用于主机服务器的 php 脚本返回的 404。

recursive_error_pages off;
error_page 404 = @missing;

location @missing {
    proxy_pass http://anotherserver;
    proxy_read_timeout 60s;
}

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ /index.php$is_args$args;
}

所以每当 php 应用程序返回 404 时,它都会优雅地回退到另一个服务器,但问题是它无法传递 URI,因为它位于命名块内。

如何配置 nginx 仅在主机服务器的应用程序返回 404 时代理到 另一个服务器

【问题讨论】:

  • 你试过nginx upstreamPS:我认为这是一个更适合超级用户或服务器故障的问题

标签: php nginx fpm


【解决方案1】:

您可以使用nginx upstream 在位置块中传递另一个服务器:

recursive_error_pages off;
error_page 404 = @missing;

upstream anotherserver404 {
    server anotherserver.only404.com:80;
}

location @missing {
    proxy_pass http://anotherserver404;
    proxy_read_timeout 60s;
}

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ /index.php$is_args$args;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2020-05-03
    • 2019-09-04
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多