nginx proxypass content 404s when adding caching location block

Posted by Thermionix on Server Fault See other posts from Server Fault or by Thermionix
Published on 2011-11-22T04:56:52Z Indexed on 2011/11/23 1:58 UTC
Read the original article Hit count: 728

Filed under:
|
|

Below is my nginx conf - the location block for adding expires max to content is causing issues with content from the /internal proxied sites.

nginx error log;

2011/11/22 15:51:23 [error] 22124#0: *2 open() "/var/www/internal/static/javascripts/lib.js" failed (2: No such file or directory), client: 127.0.0.1, server: example.com, request: "GET /internal/static/javascripts/lib.js?0.6.11RC1 HTTP/1.1", host: "example.com", referrer: "https://example.com/internal/"

browser error;

lib.js Failed to load resource: the server responded with a status of 404 (Not Found)

commenting out the expires max location block allows the proxied sites to work as intended.

Config files;

proxy.conf

location /internal {
    proxy_pass        http://localhost:10001/internal/;
    include proxy.inc;
}
 .... more entries ....

sites-enabled/main

server {
    listen   80;
    include www.conf;
}
server {
    listen 443;

    include proxy.conf;
    include www.conf;

    ssl on;
}

www.conf

root /var/www;
server_name example.com;

location / {
    autoindex off;
    allow all;
    rewrite ^/$ /mainsite last;
}

location ~*  \.(jpg|jpeg|gif|css|png|js|ico)$ {
    expires max;
}

# hide protected files
location ~* \.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$ {
    deny all;
}

location ~ \.php$ {
    fastcgi_index index.php;
    include fastcgi_params;
    if (-f $request_filename) {
            fastcgi_pass 127.0.0.1:9000;
    }
}

proxy.inc

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_redirect          off;
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;

© Server Fault or respective owner

Related posts about nginx

Related posts about reverse-proxy