我有一个 nginx + Thin + Rails 3.2 设置。目前我正在尝试设置 nginx,以便它可以直接提供缓存页面。
但是 nginx 仍然在以下 nginx 配置文件中将 *.html 请求传递给 Rails。html 文件存在于 public 文件夹中,nginx 确实找到了它们,只是它们仍然传递给 Rails。
upstream site {
server unix:/home/site/deploy/site/shared/pids/thin.0.sock;
}
server {
listen 80;
server_name www.example.com;
rewrite ^(/.*) http://example.com$1 permanent;
}
# asset server
server {
listen 80;
server_name assets.example.com;
expires max;
add_header Cache-Control public;
charset utf-8;
root /home/site/deploy/site/current/public/;
}
# frontend
server {
listen 80;
server_name .example.com;
charset utf-8;
root /home/site/deploy/site/current/public/;
index index.html;
location ~* ^.+.(jpg|jpeg|gif|png|swf|zip|rar|doc|xls|exe|pdf|ppt|txt|tar)$ {
root /home/site/deploy/site/current/public/;
expires max;
break;
}
# serve static files
if (-f $request_filename) {
break;
}
gzip on;
location / {
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;
if (-f $request_filename) {
break;
}
if (-f $document_root/cache/$host/$uri/index.html) {
rewrite (.*) /cache/$host/$1/index.html break;
}
if (-f $document_root/cache/$host/$uri.html) {
rewrite (.*) /cache/$host/$1.html break;
}
if (-f $document_root/cache/$host/$uri) {
rewrite (.*) /cache/$host/$1 break;
}
proxy_pass http://site;
break;
}
}
我是 nginx 新手,这个配置文件是从我之前没有做过的项目中复制过来的,所以这可能是一个非常新手的问题。