1

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;

}

Kevin Parker
  • 757
  • 1
  • 13
  • 32
  • 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 09:20

1 Answers1

2

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;
}
skinp
  • 749
  • 1
  • 7
  • 19