小编Wen*_*zil的帖子

如何更改 nginx 中代理服务器响应的状态代码?

我很难将 nginx 配置为充当公共 S3 端点的代理。我的用例需要更改 S3 响应的状态代码,同时保留响应负载。

S3 返回的可能状态代码包括 200 和 403。对于我的用例,我需要将这些状态代码映射到 503。

我尝试了以下不起作用的方法:

location ~* ^/.* {
  [...]
  proxy_intercept_errors on;
  error_page             200 =503 $upstream_http_location
}
Run Code Online (Sandbox Code Playgroud)

Nginx 输出以下错误:

nginx:/etc/nginx/nginx.conf:xx 中的 [emerg] 值“200”必须介于 300 和 599 之间

这是一个更完整的片段:

server {
  listen       80;

  location ~* ^/.* {
    proxy_http_version         1.1;
    proxy_method               GET;
    proxy_pass                 http://my-s3-bucket-endpoint;
    proxy_pass_request_body    off;

    proxy_set_header       Content-Length "";
    proxy_set_header       Connection "";
    proxy_set_header       Host my-s3-bucket-endpoint;
    proxy_set_header       Authorization '';

    proxy_hide_header      x-amz-id-2;
    proxy_hide_header      x-amz-request-id;
    proxy_hide_header      Set-Cookie;
    proxy_ignore_headers   "Set-Cookie";

    proxy_cache            S3_CACHE;
    proxy_cache_valid      200 403 503 1h; …
Run Code Online (Sandbox Code Playgroud)

proxy nginx proxypass

5
推荐指数
1
解决办法
7464
查看次数

标签 统计

nginx ×1

proxy ×1

proxypass ×1