我有一个托管在Amazon S3上的网页,但我不希望http响应代码为200
。该页面是一个维护页面,当我关闭主要网站进行维护时,会将流量重定向到该页面。
我希望Amazon S3页面包括以下内容的响应标头:
HTTP/1.1 503 Service unavailable
Amazon提供了向S3对象添加一些元数据的功能,但是http状态代码没有任何内容。
是否有可能?
在Amazon允许来自S3的自定义状态代码之前,这是使用nginx的一种解决方法。
我们监视是否存在特定文件,该文件充当维护模式的“ ON开关”。如果找到,我们proxy_pass
将向S3请求-技巧是return 503
将503状态代码的处理但重定向到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;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句