Pre
在我的网站上,我设置了图片,以便您可以请求一个自定义大小。
file.jpg?s=wXh //w and h are numbers in pixels
如果file.jpg的大小为wXh,我从S3提供服务。
如果file.jpd不存在于此大小。我以正确的大小创建它,将其流到客户端,并将其保存到S3,以便下次它将存在。
现在,对于NGINX来说,这是一个相当复杂的情况。
如果文件存在,我如何告诉nginx从S3提供服务,或者如果不存在文件,如何将请求转发到我的节点服务器?
谢谢
更新:
尝试使用@Alexey Ten建议的方法,这似乎很有希望,我相信这是正确的方法,但我仍然有麻烦。
这是我在conf文件中使用的代码:
# domain.com/pubstore is where we have node route to s3
# the format of the string we use is the path on the s3 server.
# domain.com/pubstore/folder1/folder2/file.ext will tell node to
# fetch the file from [bucket]/folder1/folder2/file.ext
# location /pubstore/ {
# proxy_pass http://bucketName.s3.amazonaws.com/;
# proxy_intercept_errors on;
# error_page 404 = @nodejs;
# }
# location @nodejs {
# proxy_pass http://localhost:8080/pubstore/;
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection 'upgrade';
# proxy_set_header Host $host;
# proxy_cache_bypass $http_upgrade;
# gzip_disable msie6;
# gzip on;
# gzip_vary on;
# gzip_types image/svg+xml image/x-icon;
# gzip_min_length 256;
# }
当我试图执行nginx时,我得到了以下错误:
Starting nginx: nginx:
[emerg] "proxy_pass" cannot have URI part in location given by
regular expression, or inside named location, or inside "if" statement,
or inside "limit_except" block
关于纠正这个问题的想法?
发布于 2016-09-13 00:23:24
您应该将请求传递给S3,如果它返回404错误,则应该将其重新发送到节点。就像这样:
location /path/to/file/ {
proxy_pass http://s3.domain/path/to-file/on/s3/;
proxy_intercept_errors on;
error_page 404 = @nodejs;
}
location @nodejs {
proxy_pass http://node.server;
}
https://stackoverflow.com/questions/39448449
复制相似问题