logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Apache proxypass and webrick redirect
Author
harpenden_baz



Joined: 28 Sep 2012
Posts: 6
Location: UK, Harpenden

PostPosted: Mon 01 Oct '12 17:52    Post subject: Apache proxypass and webrick redirect Reply with quote

Hi guys,
I have an Apache 2 server running on CentOS as well as webrick running a rails app on port :3000.
I'm trying to get Apache to redirect all traffic to port :80 to the rails app. There are articles all over the web on how to do this using proxypass to forward all requests to that port. So I have this in my httpd.conf:

<VirtualHost *:80>
ServerName exampledomain.co.uk
ServerAlias www.exampledomain.co.uk
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>

This doesn't seem to work at all, I just get a
I am loading the proxy module further up my conf file. Can anyone help? am I missing something?
Thanks
Barry
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 02 Oct '12 17:26    Post subject: Reply with quote

do you loaf mod_proxy.so and mod_proxy_http.so ?

anythin in the error log?
Back to top
harpenden_baz



Joined: 28 Sep 2012
Posts: 6
Location: UK, Harpenden

PostPosted: Wed 03 Oct '12 16:15    Post subject: Reply with quote

Hey James,
Yes I'm loading both of those modules.
I have this setting just before my virtual host config:

ProxyRequests Off
ProxyPreserveHost On
ProxyTimeout 1000
TimeOut 1000

Not too sure what they actually do?????
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 04 Oct '12 14:43    Post subject: Reply with quote

harpenden_baz wrote:

Not too sure what they actually do?????


mod_proxy.so is to enbale proxy functionality for apache.
mod_proxy_http.so adds the http protocol to the proxy so that you can connect to http://...

your apache error log? Is there something to find about this?

You should decrese the ProxyTimeout to a few seconds to see if the app is connectable. 1000 seconds is way too long.


Did you restart apache after making the config changes?
Back to top
harpenden_baz



Joined: 28 Sep 2012
Posts: 6
Location: UK, Harpenden

PostPosted: Mon 08 Oct '12 20:22    Post subject: Reply with quote

There's no error now other than a 404!
And no error is the logs.
The redirect just doesn't happen?
Is there another way to do this with mod_redirect or something?
Thanks
Barry
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 08 Oct '12 21:03    Post subject: Reply with quote

Hm, a 404 doesn't seem that bad.

a) make sure the DNS from exampledomain.co.uk points to that apache. In worst case just do a entry in the hosts file and see if you can see than anything.

b) you can open localhost:3000/ in your browser where apache in on?

c) You configure the directoryIndex correctly so that it opens the defualt file from the backend server?

d) it is recommend to define an access log and error log for this vhost so that you can see what is going on. (You can disable it later again)
Back to top
harpenden_baz



Joined: 28 Sep 2012
Posts: 6
Location: UK, Harpenden

PostPosted: Tue 09 Oct '12 11:36    Post subject: Reply with quote

Thanks for your help James:

a) make sure the DNS from exampledomain.co.uk points to that apache. In worst case just do a entry in the hosts file and see if you can see than anything.

>> I have done this and all looks good

b) you can open localhost:3000/ in your browser where apache in on?

>> Yes I can view the RoR site on localhost:3000 and on 0.0.0.0:3000

c) You configure the directoryIndex correctly so that it opens the defualt file from the backend server?

>> Can you explain this one a bit more?

d) it is recommend to define an access log and error log for this vhost so that you can see what is going on. (You can disable it later again)

>> The logs are all clean no errors other than a 404.

Further to this I seem to be able to redirect traffic out to various websites but not internally to port 3000? So if I do:


ProxyPass / http://www.google.com/
ProxyPassReverse / http://www.google.com/

It works! Does this help?


Many Thanks
Barry
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 09 Oct '12 12:07    Post subject: Reply with quote

harpenden_baz wrote:

Further to this I seem to be able to redirect traffic out to various websites but not internally to port 3000? So if I do:


ProxyPass / http://www.google.com/
ProxyPassReverse / http://www.google.com/

It works! Does this help?



That might help. I forgot that the "newer" OSs often resolve localhost to IPv6 localhost = ::1
And when your rails app serves only on IPv4 that won't work.

You may try

Code:

ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
Back to top
harpenden_baz



Joined: 28 Sep 2012
Posts: 6
Location: UK, Harpenden

PostPosted: Tue 09 Oct '12 12:29    Post subject: Reply with quote

OK now I get this in the error log:

[Tue Oct 09 11:32:17 2012] [error] proxy: HTTP: disabled connection for (127.0.0.1)
[Tue Oct 09 11:34:07 2012] [error] (13)Permission denied: proxy: HTTP: attempt to connect to 127.0.0.1:3000 (127.0.0.1) failed
[Tue Oct 09 11:34:07 2012] [error] ap_proxy_connect_backend disabling worker for (127.0.0.1)

Any ideas?
Thanks
Baz
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 09 Oct '12 12:39    Post subject: Reply with quote

harpenden_baz wrote:

Any ideas?


That is because of SE Linux.

Code:
/usr/sbin/setsebool httpd_can_network_connect true


Or you can also set the security settings, Go to Security Level configurations and Change Tab to SELinux. And modify SELinux policy Check “Allow HTTPD scripts and modules to connect to the network” under HTTPD service.
Back to top
harpenden_baz



Joined: 28 Sep 2012
Posts: 6
Location: UK, Harpenden

PostPosted: Tue 09 Oct '12 13:27    Post subject: Reply with quote

That worked! Thanks I would never have figured that one out alone!
Back to top


Reply to topic   Topic: Apache proxypass and webrick redirect View previous topic :: View next topic
Post new topic   Forum Index -> Apache