我的 Nginx 配置中用于添加内容的位置块expires max
是否导致代理站点的内容出现问题/internal
。注释掉expires max
位置块可使代理站点按预期工作。
Nginx 错误日志
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/"
浏览器错误
lib.js Failed to load resource: the server responded with a status of 404 (Not Found)
代理配置文件
location /internal {
proxy_pass http://localhost:10001/internal/;
include proxy.inc;
}
.... more entries ....
站点启用/主要
server {
listen 80;
include www.conf;
}
server {
listen 443;
include proxy.conf;
include www.conf;
ssl on;
}
閣下網站
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_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;
答案1
我最终将 expires 块移到了/
location 块内
location / {
autoindex off;
allow all;
rewrite ^/$ /mainsite last;
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
}
}