【发布时间】:2011-11-06 14:38:05
【问题描述】:
我有一个包含动态和静态内容的应用程序。我使用 nginx 作为这个应用程序的前端。当请求动态内容时,请求被转发到一个 unix 套接字(到一个 node.js 应用程序),这部分工作得很好。我添加了一个“位置”指令来提供静态内容,但这部分不起作用,尽管文件夹“/home/test/my_app/static”确实存在,但每次我都会收到 404 错误。
这是我的 nginx 配置文件:
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;
}
}
有什么想法吗?
【问题讨论】:
标签: configuration nginx