Proxy requests to virtual host in by path prefix - ruby-on-rails

I'm running multiple Rails applications on TorqueBox. Each application is mounted on a different web context, e.g., localhost:8080/app1 and localhost:8080/app2 (configured via TorqueBox). Apache is configured to accept requests to app1.domain.com and app2.domain.com via virtual hosts. However, I'm running into problems where some application paths (form submission paths and others) expect to be preceeded by /app1, e.g., http://app1.domain.com/app1/rest/of/path instead of the correct http://app1.domain.com/rest/of/path.
How can I configure Apache so that the requests to http://app1.domain.com/app1/... are made to the correct path (i.e., without the leading /app1)? I've tried doing this with redirects but that doesn't work since they force a GET request and the POST data is lost in the process.
This is my current Apache config:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
ProxyRequests Off
ProxyPreserveHost On
NameVirtualHost *:80
<VirtualHost *:80> # There are multiple vhosts like this one, for different apps.
ServerName app1.domain.com
ProxyPass / http://127.0.0.1:8080/app1/
ProxyPassReverse / http://127.0.0.1:8080/app1/
</VirtualHost>

I solved this problem by using a web host instead of a web context in the TorqueBox configuration. After that, getting the Apache configuration to work was no problem since different apps were not under specific context paths.
So, instead of this (in config/torquebox.rb):
TorqueBox.configure do
web do
context '/app1'
end
end
You should do this:
TorqueBox.configure do
web do
host 'app1.domain.tld'
end
end

Related

Apache + Passenger Rails app failing with a 403 error

I currently have a rails app that works locally but at the moment of deploying the app i'm having an error configuring the server.
I followed the steps here, and i'm stuck on step 6. Instead of seeing the rails webpage i got
Inside /etc/apache2/sites-available/tesis.conf i got
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/tesis/public
RailsEnv development
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html/tesis/public">
Options -MultiViews
Require all granted
Allow from all
</Directory>
And the rails app is located at /var/www/html/tesis/public, so that makes sense, but the odd thing is that debugging the apache error logs (/etc/apache2/sites-available/tesis.conf) i see:
[client 143.244.50.172:44448] AH01630: client denied by server configuration: /home/deploy/tesis/public/config
Why apache is going to that path instead of the one i specify on the configuration file?

Overwhelmed with Apache mod passenger / Ruby on Rails

i tried to migrate a ruby on rails project from a server to another.
Everything is pretty much working. Now only mod passenger and apache gives me big problems.
Just as a not - i set the following command else i couldnt start apache "a2enmod mod_access_compat"
Now here is my config file:
LoadModule passenger_module /home/homeuser/.rvm/gems/ruby-2.1.10/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/homeuser/.rvm/gems/ruby-2.1.10/gems/passenger-4.0.41
PassengerDefaultRuby /home/homeuser/.rvm/gems/ruby-2.1.10/wrappers/ruby
</IfModule>
ServerAdmin ME
ServerName server.ip
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#DocumentRoot /srv/www/vhosts/default/
DocumentRoot /home/homeuser/projectx/public/
# if not specified, the global error log is used
ErrorLog /var/log/apache2/error_log
CustomLog /var/log/apache2/access_log combined
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName Off
# configures the footer on server-generated documents
ServerSignature On
#ScriptAlias /cgi-bin/ "/srv/www/vhosts/default/cgi-bin/"
#<Directory "/srv/www/vhosts/default/cgi-bin">
# AllowOverride None
# Options +ExecCGI -Includes
# Order allow,deny
# Allow from all
#</Directory>
<Directory "/home/homeuser/projectx/public/">
#
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Options Multiviews Indexes
RailsEnv development
</Directory>
</VirtualHost>
Now the problem.
On my other server i can just call the IP of the server, and the rails installation just opens fine.
Here is just goes into the "public" directory and indexes me all its contents.
I know a fix where you can alter the routes within the routes config file:
get '/something', to: 'start#index'
Now i can reach the website via browser if i type the adress:
server.ip/something
But like i said - i need a pretty much identical version.
So what i need is being able to reach the site via:
server.ip and not server.ip/something
Any help appreciated. Me and my collegues are going crazy about this :-).
EDIT:As an answer to #Aakash Gupta-
Actually "something" is just any string i set in the routes file so i can enter the webapp via browser. What i want instead is to enter the webapp just by typing the pure IP of the server into the browser. Without the "something". So lets make an example: If i type into the browser: www.website.com - it doesnt work. But if i set a route in the routes file, as shown above, i can enter the site by e.g. www.website/start.com or www.website/whatever.com. But i really dont want to have to type something after the url as it has effects on other stuff. So i just want to type in the pure domain/ server address which would be website.com. And then the webapp should appear - but instead i just get shown the contents of the public folder, as there is no index file inside. But on my other server mod passenger is clever enough to still start the webapp, even if i set the public folder is a document root. Hope that clarifies my problem. Like i said - i didnt have problems on other servers. : /

How to use geminabox with Apache web server

I want to use geminabox with Apache web server. I have searched a lot on web but could not find any concrete information. Can some one please let me know how to do this ? Will appreciate detailed suggestions.
An easy way to use Geminabox with Apache is to configure a HTTP Reverse Proxy.
For this configuration, you just need two files:
1) The config.ru just like the example in the README.md file in the geminabox repository:
require "rubygems"
require "geminabox"
Geminabox.data = "include here the data path"
run Geminabox::Server
To run the server use rackup command. This will start the server in the 9292 port. If you want to change the port number use rackup -p XXXX.
2) In the Apache side, make sure that you have the mod_proxy and the mod_proxy_http installed. If yes, just include the following lines into your Apache config file:
ProxyRequests Off
ProxyPass / http://localhost:9292/
ProxyPassReverse / http://localhost:9292/
Restart the Apache and it is done!
geminabox is a ruby application, and just like all ruby applications, Apache does not support them out of the box.
With that said, a simple Google of how to use ruby applications with Apache lead me to this, which lead me to this. I have no experience with this tool. However, it is suggested by the rails team, so it has to have some merit.
I did work with Apache VirtualHost.
In folder /etc/httpd/conf.d/ create a file gems.conf, so add it to the file:
<VirtualHost *:80>
ServerName gems.mydomain
ServerAlias gems.local
DocumentRoot /var/railsapps/gems/public
</VirtualHost>
Where /var/railsapps/gems is the folder that have the config.ru.
The domain gems.mydomain must be in your DNS or /etc/hosts

Rails not rendering assets over SSL (404 Not Found error)

I am kind of new to Rails and am struggling with an issue that is preventing my assets to be found if I try to access my test app using an SSL connection.
As an example of what I am referring to, if you try to access
http://domain.com/testapp the default rails page loads fine and I have no issues at all.
You can also access a page I created using this route
http://domain.com/testapp/static_pages/home
However the same address, if accessed via HTTPS is returning 404 errors for all of my assets. I am also unable to access any routes (they all return 404).
https://domain.com/testapp
https://domain.com/testapp/static_pages/home
I am currently using an Apache server with Passenger installed, and here is what my virtual host configuration looks like:
<Directory /var/www/testapp/public>
PassengerEnabled on
PassengerAppRoot /var/www/testapp
RailsBaseURI /testapp
</Directory>
Any ideas of why this might be happening?
Thanks,
Rog
Thanks all, I finally figured out what was going on so in the interest of others having the same issue, the virtual host configuration was only being applied to the default port (80) so I had to specify port 443 as well.
<VirtualHost *:80 *:443>
<Directory /var/www/testapp/public>
PassengerEnabled on
PassengerAppRoot /var/www/testapp
RailsBaseURI /testapp
</Directory>
</VirtualHost>
For people using Media Temple's DV server, this configurations has to be specified in two separate files (make sure you remove the VirtualHost tags).
vhost.conf
vhost_ssl.conf
And don't forget to restart apache.
/usr/sbin/apachectl -K graceful

ruby rails passenger apache2 using Basic LDAP authentication in httpd.conf

I have a site that I want to force a user to log in via LDAP before they can see the front page of the website. This works with generic webpages fine, but doesn't work with a rails site running passenger on apache2. I've seen some references that this is because passenger doesn't respect the Directory command (or picks up before it gets to that directive). Is there a way to make this happen or do I need to add devise to the site instead?
<VirtualHost *:80>
ServerName test.example.com
DocumentRoot "/www/software/rails_site/current/public"
ErrorLog "/www/logs/software/rails_site/error_log"
CustomLog "/www/logs/software/rails_site/access_log" common
DirectoryIndex index.html
RailsEnv production
<Directory "/www/software/rails_site/current/public">
AuthType Basic
AuthName "Secure portal"
AuthBasicProvider ldap
AuthzLDAPAuthoritative on
AuthLDAPURL "info"
AuthLDAPBindPassword "pass"
require ldap-user usernames
Order deny,allow
Satisfy Any
</Directory>
</VirtualHost>
The above doesn't prevent the site from loading or do any challenge when first trying to load the site.
Try placing the authentication directives inside a Location instead of a Directory so that they will be triggered first by the incoming URI. Apparently Passenger has an order of operations associated with Directory directives.
This old post confirms that what you're trying to do (at least used to be) possible:
http://groups.google.com/group/phusion-passenger/browse_thread/thread/bb0ccee6b4a45bc0/429a34fb66dbde6d

Resources