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

7
  • 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. Commented Jan 10, 2014 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. Commented Jan 11, 2014 at 1:11
  • Is it possible to server static content separate for js and rest Commented Jan 11, 2014 at 1:12
  • could you please add this new info to your question, it's unreadable in comments. Commented Jan 11, 2014 at 11:25
  • possible duplicate of Load balance request traffic with muiltiple Node servers using NGINX Commented Jun 30, 2014 at 20:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.