nginx处理错误时无法使用proxy_pass

时间:2019-01-07 03:23:45

标签: nginx

我正在尝试配置nginx来提供s3存储桶中的错误页面。

为此,我的配置如下所示:

A function cannot be called unless it was defined in the same file or one loaded before the attempt to call it.

A function cannot be called unless it is in the same or greater scope then the one trying to call it.
It should work like this:

1) within data.js
function go_call(){
alert('working');
}

2) Within file2.js
function clickedTheButton() {
go_call();
}

3) Html File:
<html>
<head>
</head>
<body>
<button onclick="clickedTheButton()">Click me</button>
<script type="text/javascript" src="data.js"></script>
<script type="text/javascript" src="file2.js"></script>
</body>
</html>

我的期望是,所有访问该网站但未找到的内容都将发送到@fallback位置。然后,我想用我的404页面的实际位置重写URL,然后发送到s3存储桶。我不想只是302重定向到404页面。

问题是未执行proxy_pass指令。相反,它只是在本地查找我重写的URL。

在下面查看我的访问日志:

location / {
    error_page 404 = @fallback;
}

location @fallback {
    rewrite ^ /my-s3-bucket/404.html;
    proxy_pass https://s3.ap-northeast-2.amazonaws.com;
}

我向www.dev.mywebsite.com.au/sdfd请求,但未找到。 “ sdfs”已重写为“ my-s3-bucket / 404.html”,但不是将其传递到https://s3.ap-northeast-2.amazonaws.com的代理,而是在本地/ etc / nginx / html目录中查找它。

我的nginx版本是1.15.2

1 个答案:

答案 0 :(得分:0)

如果要在同一rewrite...break块中处理重写的URI,请使用location。有关更多信息,请参见this document

例如:

location @fallback {
    rewrite ^ /error/404.html break;
    proxy_pass https://example.com;
}