首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如果存在静态文件,则安装nginx以提供静态文件;如果不存在,则让服务器创建该文件。

如果存在静态文件,则安装nginx以提供静态文件;如果不存在,则让服务器创建该文件。
EN

Stack Overflow用户
提问于 2016-09-12 10:39:43
回答 1查看 672关注 0票数 1

Pre

在我的网站上,我设置了图片,以便您可以请求一个自定义大小。

代码语言:javascript
代码运行次数:0
运行
复制
file.jpg?s=wXh //w and h are numbers in pixels

如果file.jpg的大小为wXh,我从S3提供服务。

如果file.jpd不存在于此大小。我以正确的大小创建它,将其流到客户端,并将其保存到S3,以便下次它将存在。

现在,对于NGINX来说,这是一个相当复杂的情况。

如果文件存在,我如何告诉nginx从S3提供服务,或者如果不存在文件,如何将请求转发到我的节点服务器?

谢谢

更新:

尝试使用@Alexey Ten建议的方法,这似乎很有希望,我相信这是正确的方法,但我仍然有麻烦。

这是我在conf文件中使用的代码:

代码语言:javascript
代码运行次数:0
运行
复制
   # 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时,我得到了以下错误:

代码语言:javascript
代码运行次数:0
运行
复制
 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 

关于纠正这个问题的想法?

EN

回答 1

Stack Overflow用户

发布于 2016-09-13 08:23:24

您应该将请求传递给S3,如果它返回404错误,则应该将其重新发送到节点。就像这样:

代码语言:javascript
代码运行次数:0
运行
复制
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;
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39448449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档