• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 999
  • Last Modified:

nginx: match subdirectories and serve statically

Hi,

we've got nginx installed and would like to create the following behaviour, when serving files for the same domain name (www.example.com):

- JavaScript files: are in the subdirectory "js" and should be served statically. The URL includes a version number that should be filtered out, e.g. www.example.com/js/1234/test.js or www.example.com/js/5678/test.js. Both URLs point to the same file "test.js" which is in the directory DOCUMENT_ROOT/js/
- CSS files: are in the subdirectory "css" and should be served statically. The URL includes a version number that should be filtered out, e.g. www.example.com/css/1234/test.css or www.example.com/js/5678/test.css. Both URLs point to the same file "test.css" which is in the directory DOCUMENT_ROOT/css/
- PHP files: should be served via fastcgi process. The URL either ends with "php" or has NO file ending at all, e.g. www.example.com/test or www.example.com/test.php which both point to the script "test.php" in the directory DOCUMENT_ROOT

What is the according configuration needed in nginx?

Thanks and bests
0
semantique
Asked:
semantique
1 Solution
 
semantiqueAuthor Commented:
Solution I was looking for:


location ~* \.(js)$ {
    rewrite  ^(/\d*)/(.*)$  /$2 last;
    add_header Content-Type "application/x-javascript";
  }

  location ~* \.(css)$ {
    rewrite  ^(/\d*)/(.*)$  /$2 last;
    add_header Content-Type "text/css";
  }
  location = / {
    fastcgi_param  SCRIPT_FILENAME $document_root$script_name;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    include        fastcgi_params;
  }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now