Proxy uploading

Tim Child tim at timc3.com
Thu Jul 29 17:11:13 MSD 2010


On 29 Jul 2010, at 14:49, Igor Sysoev wrote:

> On Thu, Jul 29, 2010 at 11:45:50AM +0200, Tim Child wrote:
> 
>> Hi,
>> 
>> Currently using Nginx 0.7.65-1 on Ubuntu 10.04. I need to have my application upload files to another backend, so I thought I could use proxy pass, and have a certain URL be proxied to another machine (proxy_pass http://upstreamserver.com:8080/API/import) . The URL would be http//portalvm/API/upload/ that I upload to.
>> 
>> Otherwise proxy to Apache running on 127.0.0.1:8000.
>> 
>> What is happening is that it is indeed proxying but I am getting a 404 error from the upstreamserver.com even though the URL that I am using looks correct. The logs (error.log in Debug mode) are saying:
>> 
>> http proxy header:
>> "POST /API/import/raw?transferid=unique321&name=p158cr86gf1i34t099c1gkn1vh51.tmp HTTP/1.0^M
>> Authorization: Basic base64string^M
>> Host: p upstreamserver.com:8080^M
> 
> I see strange host name: "p upstreamserver.com:8080".

Actually that is my bad, as I didn't want to expose the server I was using to the whole world.

Host: upstreamserver.com:8080

> 
>> 
>>        location ~ ^/(favicon.ico|robots.txt|sitemap.xml)$ {
>>            alias /opt/media/$1;
>>            expires 30d;        
>>        }
> 
> It's better to write this as three locations:
> 
>         location = /favicon.ico {
>             root /opt/media;
>             expires 30d;        
>         }
> 
>         location = /robots.txt {
>             root /opt/media;
>             expires 30d;        
>         }
> 
>         location = /sitemap.xml {
>             root /opt/media;
>             expires 30d;        
>         }

Will do.


> 
>>        location /sitemedia {
>>            alias /opt/media/;
>>            expires 30d;            
>>        }
>>        location /API/import {
>>           error_log /var/log/nginx/error.log debug;
>>           client_max_body_size 1000M; 
>>           proxy_pass http://upstreamserver.com:8080/API/import;
> 
> These directives hide/pass header from upstream to client:

I don't need as far as I know to send the Cookie and Referer to the upstream server, but the content-length is needed for the file I think.

> 
>>           proxy_hide_header Referer;
>>           proxy_hide_header Cookie;
>>           proxy_pass_header Content-Length;
> 
>>           proxy_set_header Authorization "Basic base64string";
>>        }
>>        location / {
>>            proxy_pass http://portalvm;
>>            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;      
>>            add_header X-Handled-By $upstream_addr;      
>>        }
> 
> I do not understand, what you want to proxy:
> "/API/upload/" or "/API/import/" ?
> 

Again my bad, I mean't /API/import/

I have actually got it working when I removed a header "INDEX" that was getting sent.

Thanks,

Tim.




More information about the nginx mailing list