2011-04-23 65 views
0

我有一个轨道应用程序与子域。为什么NGinX不能重定向到我的缓存文件?

我在我的应用程序更改了默认的缓存位置,这样的模板被写入:

[APP_DIR] /公/缓存/ [子网域]/[路径]

因此,请求:

http://france.mysite.com/recipes.html 

将写入:

[my_app]/public/cache/france/recipes.html 

这是工作的罚款,该文件被写到服务器上的正确位置。

我的问题是NGinx没有提供这些缓存的文件。

我已经添加了以下到我的nginx的配置:

# catch requests to www and remove the 'www' 
    server { 
     server_name www.mysite.com; 
     rewrite^$scheme://mysite.com$request_uri permanent; 
    } 


    server { 
     server_name mysite.com *.mysite.com; 

     access_log /home/deploy/mysite/staging/current/log/access.log; 
     error_log /home/deploy/mysite/staging/current/log/error.log; 

     root /home/deploy/mysite/staging/current/public; 

     passenger_enabled on; 
     rails_env staging; 

     client_max_body_size 400M; 
     client_body_buffer_size 128k; 

     if (-f $request_filename) { 
      break; 
     } 

     # Check/files with index.html 
     if (-f $document_root/cache/$host/$uri/index.html) { 
      rewrite (.*) /cache/$host/$1/index.html break; 
     } 

     # Check the path + .html 
     if (-f $document_root/cache/$host/$uri.html) { 
      rewrite (.*) /cache/$host/$1.html break; 
     } 

     # Check directly 
     if (-f $document_root/cache/$host/$uri) { 
      rewrite (.*) /cache/$host/$1 break; 
     } 


    } 

有人能指出哪里我已经错了吗? :/

回答

0

所以我能够解决这个问题...

在NGINX的$主机变量是指在整个主机(我曾误取,把它当成子域:/)

两个解决方法:

a)改变缓存目录相匹配的完整的主机名: http://france.mysite.com => /public/cache/france.mysite.com

二)抓住来自主机的子域,并使用在如果块代替:

server { 
    server_name www.mysite.com; 
    rewrite^$scheme://mysite.com$request_uri permanent; 
} 


server { 
    server_name mysite.com *.mysite.com; 

    access_log /home/deploy/mysite/staging/current/log/access.log; 
    error_log /home/deploy/mysite/staging/current/log/error.log; 

    root /home/deploy/mysite/staging/current/public; 

    passenger_enabled on; 
    rails_env staging; 

    client_max_body_size 400M; 
    client_body_buffer_size 128k; 

    # if the maintenance file exists, redirect all requests to it 
    if (-f $document_root/system/maintenance.html) { 
    rewrite ^(.*)$ /system/maintenance.html break; 
    } 

    # if the host has a subdomain, set $subdomain 
    if ($host ~* "(.*)\.mysite.com"){ 
    set $subdomain $1; 
    } 

    # Rewrite index.html. 
    if (-f $document_root/cache/$subdomain/$uri/index.html) { 
    rewrite ^(.*)$ /cache/$subdomain/$uri/index.html break; 
    } 

    # Rewrite other *.html requests. 
    if (-f $document_root/cache/$subdomain/$uri.html) { 
    rewrite ^(.*)$ /cache/$subdomain/$uri.html break; 
    } 

    # Rewrite everything else. 
    if (-f $document_root/cache/$subdomain/$uri) { 
    rewrite ^(.*)$ /cache/$subdomain/$uri break; 
    } 
} 

我与选项B去),我觉得它的整洁

相关问题