我掙扎了一下用適當nginx
聲明。
我想要做的是相當簡單:到*.public.domain.com
任何要求,我想尋找一個緩存文件,如果一個不可用,將請求發送給乘客/ Rails的處理。nginx的try_files:404嘗試添加擴展名並回落到乘客時/ Rails的
緩存文件,如果存在的話,有.html
追加到防止目錄/文件衝突,所以/test
應該尋找/test.html
和/test/2
應該尋找/test/2.html
。
緩存文件特定於子域名,因此abc.public.domain.com
應顯示在/sites/abc
文件夾中。
下面是相關的nginx代碼:
server {
# listen/SSL stuff removed for brevity
server_name *.public.domain.com;
location ~ "^(.*)\.public\.domain\.com" {
root /var/applications/app/current/sites/$1;
try_files $request_uri.html $request_uri/index.html @passenger;
}
location @passenger {
root /var/applications/app/current/public;
passenger_enabled on;
passenger_user www-data;
}
}
在我的日誌文件中,我看到的nginx試圖加載文件而不.html擴展名。例如,我看到:/var/applications/app/current/sites/abc/test" failed (2: No such file or directory)
,但沒有嘗試加載test.html
。所以看來,子域正則表達式和根聲明工作正常;添加擴展名不是。
所以這就是問題1.
問題2是,在無法找到該文件,nginx的不回落到@passenger;
它拋出一個404而不是讓Rails的處理請求和提供服務的文件本身。
有關我在做什麼錯的任何想法?我讀了很多關於nginx
的配置,不知道錯誤在哪裏。