Is my Nginx config the location block for adding expires max
to content is causing issues with content from the /internal
proxied sites. Commenting out the expires max
location block allows the proxied sites to work as intended.
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)
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;
Antwort1
I ended up moving the expires block inside the /
location block
location / {
autoindex off;
allow all;
rewrite ^/$ /mainsite last;
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
}
}