2012-04-08 67 views
1

我想在我的應用程序中使用HTTP_IF_MODIFIED_SINCE頭來確定資源是陳舊/新鮮的,並在這些情況下呈現200/304。 在我的開發環境中一切正常,但我不能爲了我的生活讓它在生產中工作。HTTP_IF_MODIFIED_SINCE頭沒有傳遞給Rails應用程序(Nginx,Passenger)

我使用的是Passenger 3.0.11和Nginx 1.0.13。

正如您在下面看到的,我嘗試了proxy_pass_header,proxy_set_header,passenger_pass_header和passenger_set_cgi_param。最後一個實際設置了HTTP_IF_MODIFIED_SINCE標頭,但它是空的... 任何幫助/想法將不勝感激!

我的配置:

server { 
    listen    80 default_server; 
    root    /home/rails/myapp/current/public; 
    passenger_enabled on; 
    charset   utf-8; 

    proxy_pass_header If-Modified-Since; 
    proxy_set_header If-Modified-Since $http_if_modified_since; 
    passenger_pass_header If-Modified-Since; 
    passenger_set_cgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since; 

    if (-f $document_root/system/maintenance.html) { 
    rewrite ^(.*)$ /system/maintenance.html break; 
    } 

    location ~ \.(aspx|jsp|cgi)$ { 
    return 410; 
    } 

    location ~ ^/(assets)/ { 
    # http://guides.rubyonrails.org/asset_pipeline.html#server-configuration 
    # gzip_static on; 
    expires  1y; 
    add_header Cache-Control public; 

    add_header Last-Modified ""; 
    add_header ETag ""; 
    break; 
    } 
} 
+0

你需要這些指令來操縱頭文件嗎?我從來不需要這樣的東西 – 2012-04-08 09:23:44

+0

嗯,不。我沒有在應用程序中看到HTTP_IF_MODIFIED_SINCE標頭,有或沒有這些指令。 ('passenger_set_cgi_param'創建了頭部屬性,但它是空的)。也許它在Nginx之前在某處被過濾了?你可以發佈你的Nginx conf嗎? – 2012-04-08 16:51:53

回答

0

這畢竟是一個用戶錯誤。我以錯誤的格式將標題發送到應用程序(IF_MODIFIED_SINCE而不是If-Modified-Since)。修復後,它沒有任何額外的指令。

1

得到它與非標頭的工作,包含下劃線,做到這一點你在nginx.conf文件HTTP或服務器塊中:

underscores_in_headers on; 
ignore_invalid_headers off; 

,並在服務器塊:

proxy_pass_header HTTP_IF_MODIFIED_SINCE 

如果您有需要處理的遺留HTTP標頭,並且其中包含下劃線,這可能很有用。

相關問題