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
semantiqueAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.