Tom*_*Tom 6 amazon-s3 http-response-codes
我有一个在Amazon S3上托管的网页,但我不想要http响应代码200.该页面是一个维护页面,当我将主网站关闭进行维护时,我将重定向流量.
我希望Amazon S3页面包含一个响应头:
HTTP/1.1 503 Service unavailable
Run Code Online (Sandbox Code Playgroud)
亚马逊能够向S3对象添加一些元数据,但http状态代码没有任何内容.
可能吗?
Tom*_*Tom -1
在 Amazon 允许来自 S3 的自定义状态代码之前,这里有一个使用 nginx 的解决方法。
我们监视特定文件的存在,该文件充当维护模式的“ON 开关”。如果找到,我们会proxy_pass向 S3 发出请求 - 技巧是将return 503503 状态代码的处理重定向到 nginx“指定位置”。
示例 nginx conf 文件(仅显示相关位):
server {
...
# Redirect processing of 503 status codes to a nginx "named location".
error_page 503 @maintenance;
# "Maintenance Mode" is off by default - Use a nginx variable to track state.
set $maintenance off;
# Switch on "Maintenance Mode" if a certain file exists.
if (-f /var/www/app/maintenanceON) {
set $maintenance on;
}
if ($maintenance = on) {
# For Maintenance mode Google recommend using status code: "503 Service unavailable".
return 503;
}
...
location @maintenance {
# Redirect the request to a static maintenance page hosted in Amazon S3.
# Note: Use proxy_pass instead of rewrite so we keep the 503 code (otherwise nginx serves a 302 code)
rewrite ^(.*)$ /index.html break;
proxy_pass http://bucketname.s3-website-us-east-1.amazonaws.com;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1848 次 |
| 最近记录: |