2011-08-30 65 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

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