2

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_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 ?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.