1

Hi i am using nginx to deploy nodejs application to serve static files.static files are served using nignx and dynamic contents are served by nodejs .

so based on the location routing i need to give request to two different nodejs application

server {
listen 80;
server_name  localhost;
location /planner.in/ { 
    proxy_pass http://localhost:3000;
    access_log planner; 
}
location ~* ^(planner.in).*.+\.(js)$ {        
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://localhost:8181;
    proxy_redirect  off;
}
location ~* ^(planner.in).*.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|flv|swf|woff|eot|ttf|svg|html|htm)$ {
    proxy_pass http://localhost:8182; 
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}
}
server {
listen 8181;
server_name  localhost;

location /planner.in/ {
    root   www/planner/public/;
    index  index.html;

    access_log planner_js; 
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}
}
server {
listen 8182;
server_name  localhost;

location /planner.in/ {
    root   www/planner/public/;
    access_log planner_others; 
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}
}

The above is my configuration file now i cannot serve my index.html file

pinging: localhost/planner.in/ through 404 error

location /planner/{} should route index.html
location /planner/api/ {} should route node dynamic content
location ~* ^(labs.in).*.+\.(js)$ {} should route only js file
location ~* ^(labs.in).*.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp‌​|rtf|flv|swf|woff|eot|ttf|svg|html|htm)$ {} should route only extension mentioned above.

Is it possible to serve static content separately for js and rest(css,fonts,images....)

can any help me how can i route index.html file through nginx

sridhar
  • 861
  • 3
  • 10
  • 14
  • You really didn't explain what you need exactly, you provided the config but nothing else, what's wrong with the current config, and what do you want instead of it. – Mohammad AbuShady Jan 10 '14 at 22:14
  • ya thank u for ur reply.. let me explain location /planner/{} should route index.html and location /planner/api/ {} should route node dynamic content and location ~* ^(labs.in).*.+\.(js)$ {} should route only js file and location ~* ^(labs.in).*.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|flv|swf|woff|eot|ttf|svg|html|htm)$ {} should route only extension mentioned above. – sridhar Jan 11 '14 at 01:11
  • Is it possible to server static content separate for js and rest – sridhar Jan 11 '14 at 01:12
  • could you please add this new info to your question, it's unreadable in comments. – Mohammad AbuShady Jan 11 '14 at 11:25
  • possible duplicate of [Load balance request traffic with muiltiple Node servers using NGINX](http://stackoverflow.com/questions/15007485/load-balance-request-traffic-with-muiltiple-node-servers-using-nginx) – Paul Sweatte Jun 30 '14 at 20:35
  • @PaulSweatte This question is not about load balancing but request splitting (is that the right term?). – JasonMArcher Jun 30 '14 at 21:30
  • So [virtual hosts](http://stackoverflow.com/questions/9368794/how-to-use-vhosts-alongside-node-http-proxy) would be more appropriate? – Paul Sweatte Jun 30 '14 at 21:40

0 Answers0