Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Nginx configuration - one url, multiple sub folders and rails app

Posted on 2010-08-26
3
Medium Priority
?
2,024 Views
Last Modified: 2013-11-13
Hi, I have a nginx, thin set up for my rails apps. I've got 1 domain name which I can use and need to handle 20 different rails app. ...

So ... need to do this way ...

say the domain name is blah.blahblah.com

for rails app "abc", it will be accessed via a subfolder like

http://blahblah.blah.com/abc

then for rails app "def". same thing

http://blahblah.blah.com/def

I've done it this way (see code). It works if it's just for one sub folder but if I do it for say 2, there's some error. I'm not a guru in nginx, I copied this off somewhere on the web.

Please advise.

Question is how do I set this up in nginx?
upstream abc {
        server 127.0.0.1:5090;
    }

upstream def {
        server 127.0.0.1:6000;
    }

server {
            listen   80;
            server_name blah.blahblah.com;
            
            access_log /opt/x/access.log;
            error_log /opt/x/error.log;

            root   /opt/x;
            index  index.html;

            location /abc/ {
                          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_redirect off;

                          if (-f $request_filename/index.html) {
                                           rewrite (.*) $1/index.html break;
                          }

                          if (-f $request_filename.html) {
                                           rewrite (.*) $1.html break;
                          }

                          if (!-f $request_filename) {
                                           proxy_pass http://abc;
                                           break;
                          }
            }

            location /def/ {
                          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_redirect off;

                          if (-f $request_filename/index.html) {
                                           rewrite (.*) $1/index.html break;
                          }

                          if (-f $request_filename.html) {
                                           rewrite (.*) $1.html break;
                          }

                          if (!-f $request_filename) {
                                           proxy_pass http://def;
                                           break;
                          }
            }



}

Open in new window

0
Comment
Question by:binele
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 59

Expert Comment

by:Cliff Galiher
ID: 33533117
"some error?"
0
 

Author Comment

by:binele
ID: 33533306
sorry, was trying to recreate the error but it seems nginx is happy with the config now....

then started to test it but here's what's in the logs.


 [error] 4311#0: *18 open() "/opt/x/abc" failed (2: No such file or directory), client: x.x.x.x, server: blah.blahblah.com, request: "GET /abc HTTP/1.1", host: "blahblah.blah.com"


 [error] 4311#0: *18 open() "/opt/x/def" failed (2: No such file or directory), client: x.x.x.x, server: blah.blahblah.com, request: "GET /abc HTTP/1.1", host: "blahblah.blah.com"


Looks like it's not reverse proxying the request...

I've got my upstream defined

upstream abc {
        server 127.0.0.1:5060;
    }


and location defined

 location /abc/ {
                          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_redirect off;

                          if (-f $request_filename/index.html) {
                                           rewrite (.*) $1/index.html break;
                          }

                          if (-f $request_filename.html) {
                                           rewrite (.*) $1.html break;
                          }

                          if (!-f $request_filename) {
                                           proxy_pass http://abc;
                                           break;
                          }
            }

And am doing the same for "def"

Is the config correct or am I not getting this right? please advise.
0
 
LVL 59

Accepted Solution

by:
Cliff Galiher earned 2000 total points
ID: 33533694
Well, the thing that leaps out at me is that the error you listed is complaining about finding /opt/.../def
/def and /def/ are very different when it comes to pattern matching so the "missing" trailing slash is not matching your location thus is falling through and not getting proxied.
-Cliff
 
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question