【问题标题】:Concat values in NGINX config file for rewrite rule用于重写规则的 NGINX 配置文件中的 Concat 值
【发布时间】:2013-09-18 08:00:01
【问题描述】:


我正在为我的 nginx 配置文件 defualt.conf 配置重写规则以接受请求并将它们路由到 S3 存储桶。
现在我正在为 URL 的后半部分获取正确的内容,但我无法连接或添加我的 S3 存储桶的 url。

这是我的代码:

  location / {
        # This code rewrites the original request, and adds the host without www in front
        # E.g. if someone requests 
        # /directory/file.ext?param=value 
        # from the coolsite.com site the request is rewritten to 
        # /coolsite.com/directory/file.ext?param=value 
        rewrite ^(.*)$ /$host_without_www$1 break;

        # The rewritten request is passed to S3
        proxy_pass http://sites.nginx.com;
    } 

在上面的重写中,我想在/$host_without_www 之前添加site.nginx.com,这是我的存储桶名称,我尝试使用.(dot) 和unix 样式{$variable_to_concat},但没有用。
有人可以建议我正确的方法吗?
感谢您的关注

【问题讨论】:

  • 这个站点的服务器名称是什么?请求/directory/file.ext?param=value时是否要获取内容site.nginx.com/coolsite.com/directory/file.ext?param=value
  • 这是存储在s3中的静态站点结构sites.nginx.com(bucket name)/coolsite.com(folder name)/index.html(files)
  • 我搞定了。实际上,我尝试连接的 url 有语法错误。我必须为日志启用调试模式,然后检查值。这解决了问题!谢谢
  • 我再发一个简单的配置,你可以试试。

标签: php amazon-web-services nginx amazon-s3


【解决方案1】:

由于你的重写 url 与洞请求匹配,你可以使用这个简单的配置:

location / {
    proxy_pass http://sites.nginx.com/coolsite.com/;
}

这里是some examples to show how proxy_pass maps the request url

【讨论】:

  • 是的,但是如何连接变量?
  • @Matt concat 是什么意思?
猜你喜欢
  • 1970-01-01
  • 2012-08-25
  • 2016-04-10
  • 1970-01-01
  • 2016-08-16
  • 2021-09-24
  • 2016-05-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多