0
這個項目通常與apache一起服務,但我想介紹nginx作爲前端控制器來代理請求通過memcached或回退到Apache,如果沒有找到URI作爲memcached中的鍵。nginx反向prroxy給404s一切
當我通過nginx發出請求時發生了什麼是我在每個資產上都獲得了404。我可以從URL欄中的一個請求中粘貼一個資產URL並檢索它,但是具有404狀態。 404s導致大部分頁面無法呈現,但似乎正在下載資產。
我可以通過apache直接做出相同的請求,它可以很好地工作。
這裏是我的nginx的配置:
upstream memcached-upstream {
server 127.0.0.1:11211;
}
upstream apache-upstream {
server 127.0.0.1:5678;
}
server {
listen 4567;
root /vagrant;
server_name sc;
index index.php;
access_log /var/log/nginx/www.sc.com.access.log;
error_log /var/log/nginx/www.sc.com.error.log error;
location/{
# Only use this method for GET requests.
if ($request_method != GET) {
proxy_pass http://apache-upstream;
break;
}
# Attempt to fetch from memcache. Instead of 404ing, use the @fallback internal location
set $memcached_key $request_uri;
memcached_pass memcached-upstream; # Use an upstream { } block for memcached resiliency
default_type application/json; # Our services only speak JSON
error_page 404 = @fallback;
}
location @fallback {
proxy_pass http://apache-upstream;
}
}
這裏是我的nginx的訪問日誌的示例:
10.0.2.2 - - [18/Dec/2013:23:50:08 +0000] "GET /templates/assets/js/csrf.js HTTP/1.1" 404 545 "http://localhost:4567/templates/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
而且從Apache日誌相同的請求:
www.sc.com:80 127.0.0.1 - - [18/Dec/2013:23:50:08 +0000] "GET /templates/assets/js/csrf.js HTTP/1.0" 200 857 "http://localhost:4567/templates/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
任何幫助將非常感激。