2011-04-23 87 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去),我覺得它的整潔

相關問題