Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having a nodejs running on port 8000 and nginx on port 80 on same server.

I want Nginx to handle all the requests(image,css,etc) and forward js requests to nodejs server on port 8000.

Is it possible to achieve this. i have configured nginx as reverse proxy but its forwarding every request to nodejs but i want nginx to process all except js.


upstream nodejs  {
  server localhost:8000; #nodejs


location / {
 proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
 proxy_redirect off;
 proxy_buffering off;
 proxy_set_header        Host            $host;
 proxy_set_header        X-Real-IP       $remote_addr;
 proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

Update Tried This: But nothing changed,still nginx is forwarding every request to nodejs

 server {

  server_name server;

  access_log /var/log/server/access.log;
  error_log /var/log/server/error.log;

 root /var/www/static;

location / {
 root /var/www/jsfiles;
access_log on;

static assets

location ~* ^(?!\/).+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
expires max;
access_log off;


share|improve this question
Did you ever solve this? I think you need to put the static rule first. AFAIK the first match wins, so your static is never evaluated? – stwissel Aug 21 '14 at 9:20

What I generally do is seperate static content and process it in another location directive. Something like:

location ~ ^/{static|images|css,...}/ {
    root /var/www/static;

location / {
    proxy_pass http://nodejs;
share|improve this answer
can u please look at the update,i have tried your suggestion. @skinp – Kevin Parker Nov 15 '12 at 5:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.