我的 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;
}
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_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
我最終將過期區塊移到/
位置區塊內
location / {
autoindex off;
allow all;
rewrite ^/$ /mainsite last;
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
}
}