Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm setting Nginx to forward requests to several backend services using proxy_pass

A few of them I have to add rewrite rules to strip the folder off, however for this particular service, the rewrite rule isn't working on styles/images. Any tips?

~$ tail /var/log/nginx/error.log
2012/02/09 10:57:19 [error] 4103#0: *10 open() "/var/www/images/blank.gif" failed (2: No such file or directory), client: 203.xxx.xxx.xxx, server: example.net, request: "GET /images/blank.gif HTTP/1.1", host: "example.net", referrer: "https://example.net/hp/"

~$ cat /etc/nginx/proxy-control.conf; 
proxy_connect_timeout   59s;
proxy_send_timeout      600;
proxy_read_timeout      600;
proxy_buffer_size       64k;
proxy_buffers           16 32k;
proxy_pass_header       Set-Cookie;
proxy_hide_header       Vary;

proxy_busy_buffers_size         64k;
proxy_temp_file_write_size      64k;

proxy_set_header        Accept-Encoding         '';
proxy_ignore_headers    Cache-Control           Expires;
proxy_set_header        Referer                 $http_referer;
proxy_set_header        Host                    $host;
proxy_set_header        Cookie                  $http_cookie;
proxy_set_header        X-Real-IP               $remote_addr;
proxy_set_header        X-Forwarded-Host        $host;
proxy_set_header        X-Forwarded-Server      $host;
proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;

proxy_set_header        X-Forwarded-Ssl         on;
proxy_set_header        Authorization           '';

proxy_redirect         http://example.net/ /;
proxy_redirect         https://example.net/ /;


~$ tail /etc/nginx/services.conf;
location /hp {
    rewrite           ^/hp$          https://example.net/hp/           permanent;                                                       $
    rewrite           /hp/(.*)      /$1                             break;

    proxy_pass        http://192.168.1.2/;
    include           proxy-control.conf;
    include           auth-basic.conf;
}

chrome errors;

https://example.net/images/blank.gif Failed to load resource: the server responded with a status of 404 (Not Found)
https://example.net/images/final-hp-login_1x11.gif Failed to load resource: the server responded with a status of 404 (Not Found)
share|improve this question
    
I just wanted to say the English NGINX support forum is incredibly helpful and you'll often get a quick response. I'm not saying this site isn't helpful, but just for really tech specific requests on NGINX I typically post in there as well as server fault –  Anagio Mar 10 '12 at 10:31
add comment

1 Answer 1

I think your settings are incorrect. When there is a request to https://example.net/images/blank.gif it is sent to http://192.168.1.2/images/blank.gif and there will be a 404. Your two rewrites do not match, of course, because this request does not begin with /hp. Maybe you want proxy_pass http://192.168.1.2/hp?

share|improve this answer
    
the request for the image originated from the /hp/ page. URLs requested on the /hp/ need to be rewritten to include /hp/ in them. This rewriting works on other services –  Thermionix Feb 9 '12 at 10:37
    
In any case, example.net/images/blank.gif won't work, as it does not begin with /hp (this conf is for example.net, isn't it?). Only example.net/hp/images/blank.gif may work? –  jcisio Feb 9 '12 at 14:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.