nginx图像调整大小代理返回415

时间:2017-12-21 13:23:58

标签: nginx proxy

我正在尝试设置nginx图像调整大小和缓存代理。我正在我的笔记本电脑上测试这个,并有以下配置文件

proxy_cache_path /tmp/nginx-thumbnails levels=1:2 keys_zone=thumbnail_cache:16M inactive=60d max_size=200M;

server {
    listen 80;
    server_name  cache.localhost;

    rewrite_log on;
    error_log    /Users/punkish/Logs/cache.localhost.error.log notice;
    access_log    /Users/punkish/Logs/cache.localhost.access.log;

    location / {
        proxy_pass http://resize.localhost;
        proxy_cache thumbnail_cache;
        proxy_cache_key "$host$document_uri$is_args$arg_key";
        proxy_cache_lock on;
        proxy_cache_valid 30d;  # Cache valid thumbnails for 30 days.
        proxy_cache_valid any 15s;  # Everything else gets 15s.
        proxy_cache_use_stale error timeout invalid_header updating;
        proxy_http_version 1.1;
        expires 30d;
    }
}

server {
    listen 80;
    server_name resize.localhost;

    rewrite_log on;
    error_log    /Users/punkish/Logs/resize.localhost.error.log notice;
    access_log    /Users/punkish/Logs/resize.localhost.access.log;

    set $backend 'https://remotehost/files';

    # Use Google for DNS.
    resolver 8.8.8.8;  
    resolver_timeout 5s;

    proxy_buffering off;
    proxy_http_version 1.1;
    proxy_pass_request_body off;
    proxy_pass_request_headers off;

    # Clean up the headers going to and from S3.
    proxy_ignore_headers "Set-Cookie";
    proxy_set_header Host $backend;
    proxy_method GET;

    # Adjust to your preferences.
    image_filter_jpeg_quality 75;  
    image_filter_buffer 12M;
    image_filter_interlace on;

    location ~ ^/([\d-]+)/(.*)/(.*)\.(png|jpg) {    
        set $image_path '$2';
        image_filter resize $1 -;

        proxy_pass $backend/$2/$3.$4;
    }
}

使用https://remotehost/files上知道的图像进行测试,我仍然得到了415。我正在使用http://cache.localhost/300/d0d76afe-ef66-4e55-9d90-70721e54b589/figure.png进行测试,我希望在其中创建一个名为/tmp/nginx-thumbnails/d0d76afe-ef66-4e55-9d90-70721e54b589的目录,其中包含300px宽figure.png的目录,然后提供给我。我可以看到cache.localhost确实将请求转发给resize.localhost,但我的猜测是resize.localhost无法找到https://remotehost/files/d0d76afe-ef66-4e55-9d90-70721e54b589/figure.png,因此返回415。

我需要做些什么来解决这个问题?

0 个答案:

没有答案