How Does the Prefix Option Work?

已查看 424 次
跳至第一个未读帖子

Bryan Richardson

未读,
2010年6月21日 17:18:072010/6/21
收件人 thin-ruby
Hello All,

I'm trying to proxy to a Sinatra application from Nginx whenever
someone navigates to a particular path on my site. For example, my
site is example.com, and whenever anyone navigates to /planner
(example.com/planner), I'd like them to be proxied to my Sinatra app.

I figured by setting the --prefix option in Thin to "/planner",
example.com/planner would become the new root URL, and as such anytime
I redirected to something like "/users" it would actually redirect to
example.com/planner/users. This doesn't seem to be the case however.

Can someone tell me 1) what does "Mount the app under PATH" really
mean, and 2) is it possible to do what I'm trying to do?

--
Thanks!
Bryan

Marc-André Cournoyer

未读,
2010年6月21日 17:23:502010/6/21
收件人 thin...@googlegroups.com
Can you share your nginx config file.


--
You received this message because you are subscribed to the Google Groups "thin-ruby" group.
To post to this group, send email to thin...@googlegroups.com.
To unsubscribe from this group, send email to thin-ruby+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/thin-ruby?hl=en.




--
M-A
http://macournoyer.com

Bryan Richardson

未读,
2010年6月21日 17:27:502010/6/21
收件人 thin-ruby
Sure! Here are the relevant parts I think:

upstream inventory {
server 192.168.101.1:3001;
}

upstream planner {
server 192.168.101.1:3011;
}

server {
listen 80;
server_name example.com;

access_log /var/log/nginx/example-access.log;
error_log /var/log/nginx/example-error.log;

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

proxy_pass http://inventory;
}

location /planner/ {
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;

proxy_pass http://planner;
}
}

--
Thanks!
Bryan

On Jun 21, 3:23 pm, Marc-André Cournoyer <macourno...@gmail.com>
wrote:
> Can you share your nginx config file.
>
>
>
>
>
> On Mon, Jun 21, 2010 at 5:18 PM, Bryan Richardson <btri...@gmail.com> wrote:
> > Hello All,
>
> > I'm trying to proxy to a Sinatra application from Nginx whenever
> > someone navigates to a particular path on my site. For example, my
> > site is example.com, and whenever anyone navigates to /planner
> > (example.com/planner), I'd like them to be proxied to my Sinatra app.
>
> > I figured by setting the --prefix option in Thin to "/planner",
> > example.com/planner would become the new root URL, and as such anytime
> > I redirected to something like "/users" it would actually redirect to
> > example.com/planner/users. This doesn't seem to be the case however.
>
> > Can someone tell me 1) what does "Mount the app under PATH" really
> > mean, and 2) is it possible to do what I'm trying to do?
>
> > --
> > Thanks!
> > Bryan
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "thin-ruby" group.
> > To post to this group, send email to thin...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > thin-ruby+...@googlegroups.com<thin-ruby%2Bunsubscribe@googlegroups .com>
> > .

vamshidhar kuchikulla

未读,
2010年6月21日 18:25:462010/6/21
收件人 thin...@googlegroups.com
Hi Bryan

Recently i was facing some problems with multiple models, controllers,
views in sinatra so here is my solution for you, may be its helpuful
for you


Application
app
blog
M
V
C
users
M
V
C
configs
database.rb
database.yml
deploy.rb
public
javascripts

etc....
Sinatra supports mount apps, by default sinatra looks its views
in /views folder for that I set the views path in the controllers and
even helpers too... mount the app segments in config.ru and you know
one more thing I am using sequel, datamapper, and multiple databases
too mysql, postgresql etc, and sequel supports automigrations , write
the schema in the models and you are done.
I know there are few changes to the sinatra classes/modules in latest
versions, like use

[MyApp::Users,MyApp::Blog].each do |controller|
controller.set :environment, :development
end

# Mount our Main class with a base url of /
map "/" do
run MyApp::Main
end

# Mount our Blog class with a base url of /blog
map "/blog" do
run MyApp:Blog
end

hope this helps

vamshi

> --
> You received this message because you are subscribed to the Google Groups "thin-ruby" group.
> To post to this group, send email to thin...@googlegroups.com.

> To unsubscribe from this group, send email to thin-ruby+...@googlegroups.com.

Bryan Richardson

未读,
2010年6月21日 21:07:402010/6/21
收件人 thin-ruby
Sweet! The whole "map '/planner' do" approach works perfectly. Thanks!

On Jun 21, 4:25 pm, vamshidhar kuchikulla <vamshionra...@gmail.com>
wrote:

Bryan Richardson

未读,
2010年6月21日 21:31:412010/6/21
收件人 thin-ruby
Okay, so it sort of works actually. All my links work correctly, but
the redirects aren't getting the "/planner" added to the front of them
properly...

Bryan Richardson

未读,
2010年6月21日 21:40:462010/6/21
收件人 thin-ruby
Okay (again), fixed it! Not preceding redirects and links with a '/'
fixed the problems. Thanks again!

Bryan Richardson

未读,
2010年6月22日 09:27:582010/6/22
收件人 thin-ruby
Bah! Okay, so I didn't fix it for pages that are one page deep into
the sight. Not having the preceding "/" causes the link HREF to just
get appended to the current URL, so pages deeper into the sight end up
not having the right URL. :(

Does anyone know if the "prefix" option will fix my problems or how it
works?

Marc-André Cournoyer

未读,
2010年6月22日 09:51:582010/6/22
收件人 thin...@googlegroups.com
Is it possible you hardcoded the URL for those? If you hardcoded /something, it will always point to /something not /prefix/something, you have to use Rails helpers.

For more options, visit this group at http://groups.google.com/group/thin-ruby?hl=en.




--
M-A
http://macournoyer.com

Bryan Richardson

未读,
2010年6月22日 09:57:172010/6/22
收件人 thin-ruby
Yes, they are hard-coded... how do I use Rails helpers in Sinatra?

On Jun 22, 7:51 am, Marc-André Cournoyer <macourno...@gmail.com>
wrote:
> > thin-ruby+...@googlegroups.com<thin-ruby%2Bunsubscribe@googlegroups .com>
> > .
> > > > > > > For more options, visit this group athttp://
> > groups.google.com/group/thin-ruby?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "thin-ruby" group.
> > To post to this group, send email to thin...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > thin-ruby+...@googlegroups.com<thin-ruby%2Bunsubscribe@googlegroups .com>
> > .

Marc-André Cournoyer

未读,
2010年6月22日 10:14:272010/6/22
收件人 thin...@googlegroups.com
Oh... not sure what is the right way to do this in Sinatra, but you could pass an ENV variable when launching the server. eg: SITE_ROOT=/prefix ruby yourapp.rb, then build all of your links w/ this ENV["SITE_ROOT"].

To unsubscribe from this group, send email to thin-ruby+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/thin-ruby?hl=en.




--
M-A
http://macournoyer.com
回复全部
回复作者
转发
0 个新帖子