2011-08-30 69 views
2

我有一個應用程序的動態和靜態內容。我使用nginx作爲這個應用程序的前端。當請求動態內容時,請求被轉發到unix套接字(到node.js應用程序),這部分運行良好。我添加了一個「位置」指令來提供靜態內容,但這部分不起作用,儘管「/ home/test/my_app/static」文件夾確實存在,但我每次都會收到404錯誤。Nginx的服務器node.js內容+靜態內容

這是nginx的CONF我:

upstream test_sock { 
    server unix:/tmp/test.sock 
    fail_timeout=0; 
} 

server { 
    listen 15000; 
    client_max_body_size 4G; 
    server_name localhost domain.com; 

    keepalive_timeout 5; 

    location ~ /static/ { 
     if (!-f $request_filename) { 
     return 404; 
     } 
     if (-f $request_filename) { 
     root /home/test/my_app/static; 
     expires 30d; 
     } 
    } 

    location/{ 
    proxy_pass http://test_sock; 
    proxy_redirect off; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    } 
} 

任何想法?

回答

2

嗯...好吧,愚蠢的事情,我錯過了位置之前的根指令...