我注意到 nginx 没有为根域上的缓存 index.html 页面提供服务。
例如)http://dev.website/
应该提供/rails_app/public/cache/index.html
,但默认为提供文件的rails应用程序
http://dev.website/same/page
实际上是与根 url 相同的页面,但缓存为/rails_app/public/cache/same/page.html
. 有用。
基本上唯一没有命中缓存的 url 是根 url。我知道这与我的 nginx 配置有关,但我对 nginx 的知识不够了解如何修复它。
这是我的配置片段:
try_files /cache/$uri /cache/$uri.html $uri $uri/index.html $uri.html @ruby;
我确定这其中的一部分是无关的,所以有人可以帮我清理它吗?
编辑:这是我的配置...
server {
listen 80;
server_name pos;
#access_log C:/rails_apps/pos/log/nginx-access.log;
error_log C:/rails_apps/pos/log/nginx-error.log;
root C:/rails_apps/pos/public;
index index.html;
location / {
satisfy any;
allow 192.168.0.0/25;
deny all;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_read_timeout 120;
proxy_connect_timeout 120;
expires max;
add_header Cache-Control must-revalidate;
if ($request_method != GET) {
proxy_pass http://pos;
}
if ($request_uri ~ .*.search=.*) {
proxy_pass http://pos;
}
try_files /cache/$uri /cache/$uri.html $uri $uri/index.html $uri.html @ruby;
}
location ~ ^/(assets)/ {
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
location @ruby {
proxy_pass http://pos;
}
}
upstream pos {
server 127.0.0.1:3000;
}