开发者

Nginx to server node.js content + static content

开发者 https://www.devze.com 2023-03-31 12:16 出处:网络
I have an application with both dynamic and static content. I use nginx as a front end for this app. When dynamic content is requested, the request is forwarded to an unix socket (to a node.js app), t

I have an application with both dynamic and static content. I use nginx as a front end for this app. When dynamic content is requested, the request is forwarded to an unix socket (to a node.js app), this part works well. I have added a "location" directive to serve the static content but this part does not work, I get the 404 error each time despite the fact the folder "/home/test/my_app/static" does exist.

This is the nginx conf I have:

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

server {
   listen 15000;
   client_开发者_StackOverflow社区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;
  }
}

Any idea ?


hmmm... ok, silly thing, I was missing the root directive before the locations ones...

0

精彩评论

暂无评论...
验证码 换一张
取 消