English 中文(简体)
Nginx Proxy to file on Local Disk or S3
原标题:Nginx Proxy to Files on Local Disk or S3
最佳回答

这是否应当成为使用<代码>try_files的一个例子?

location /p/ {
    try_files $uri @s3;
}

location @s3{ 
    proxy_pass http://my_bucket.s3.amazonaws.com;
}

保证在S3 url中lash下

问题回答

你可以改进你与你的代理会议。 改编自https://stackoverflow.com/a/44749584:

location /p/ {
    try_files $uri @s3;
}

location @s3 {
  set $s3_bucket         your_bucket.s3.amazonaws.com ;
  set $url_full          $1 ;

  proxy_http_version     1.1;
  proxy_set_header       Host $s3_bucket;
  proxy_set_header       Authorization   ;
  proxy_hide_header      x-amz-id-2;
  proxy_hide_header      x-amz-request-id;
  proxy_hide_header      x-amz-meta-server-side-encryption;
  proxy_hide_header      x-amz-server-side-encryption;
  proxy_hide_header      Set-Cookie;
  proxy_ignore_headers   Set-Cookie;
  proxy_intercept_errors on;

  resolver               8.8.4.4 8.8.8.8 valid=300s;
  resolver_timeout       10s;
  proxy_pass             http://$s3_bucket$url_full;
}

• 由于我守卫墙哨所: 为了达到目的,你可以改进:

http {

  proxy_cache_path          /tmp/cache levels=1:2 keys_zone=S3_CACHE:10m inactive=24h max_size=500m;
  proxy_temp_path           /tmp/cache/temp;

  server {
    location ~* ^/cache/(.*) {
      proxy_buffering        on;
      proxy_hide_header      Set-Cookie;
      proxy_ignore_headers   Set-Cookie;
      ...
      proxy_cache            S3_CACHE;
      proxy_cache_valid      24h;
      proxy_pass             http://$s3_bucket/$url_full;
    }
  }

}

另一项建议是将高分辨率高至5分:

resolver                  8.8.4.4 8.8.8.8 valid=300s;
resolver_timeout          10s;

如果你开始围绕模块进行挖掘,那就有意义了,但基本上保护你的代理——绕过does-not-exist >

if (-f $request_filename) {
    break;
}
if(!-f $request_filename)
    proxy_pass  http://s3;
}

最后,我检查一下档案是否存在,如果存在的话,重新撰写这一请求。 我随后处理再写的要求,并照此办理代理。

location /p/ {
  if (!-f $request_filename) {
    rewrite ^/p/(.*)$ /ps3/$1 last;
    break;
  }
}

location /ps3/ {
  proxy_pass http://my_bucket.s3.amazonaws.com/;
}




相关问题
How to change firefox proxy from webdriver?

how can I access Firefox proxy settings from Python Webdriver and change them to make Firefox use modified proxy settings without needing to restart it?

Regex Proxy Server

I control access via a proxy server and run some regex on every request. For prototype I have used curl, regex and php. Obviously this will not put up with any serious load. Can anyone suggest and ...

Specify a Proxy in config vs code for a WSE/SOAP web service

Is there a way to specify a WSE3 proxy in the config file instead of code. I figured out how to get it working in code as follows: valservice.Proxy = new System.Net.WebProxy("http://10.192.xx.xx:...

Accessing a git repository via ssh behind a firewall

I would like to access (clone/push/pull) a private (via ssh) git repository while behind a corporate firewall that only allows http proxy access. I have written a robust Java (daemon) program (based ...

Set proxy data for an app

I have a few .NET apps which use the HttpWebRequest. My gut says i can create a config or manifest file and set the proxy data in there and .NET will automatically load it. But i dont know if that ...

热门标签