Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

nginx/sites-enabled/default/

upstream nodejs  {
  server localhost:8000; #nodejs

}

location / {
 proxy_pass  http://192.168.2.21:8000;
 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 {
    listen   192.168.2.21:80;


  server_name server;

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

 root /var/www/static;

location / {
proxy_pass http://127.0.0.1:8000;
 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 yesterday

1 Answer 1

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

 
discard

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.