rails3 : appending /app1 to apache virtual host url - ruby-on-rails-3

I just installed a Rails 3 application on a development server, and it can be loaded by using http://server:3000/
In our production setup, all applications are proxied by apache running on another server. All applications are to be accessed by http://prodserver/appX . CSS and javascripts need to be loaded when using apache proxy.
How do I revise routes.rb and change rails.root to use appX, without changing the application?

Use the ProxyPassReverse configuration command in Apache and it will rewrite URL's so you don't have to change anything in routes.rb

Related

Links and assets in grails contains no prefix, grails.app.context not working

I'm trying to deploy a Grails 2.5.3 application on a Tomcat 7 server, running behind Apache (apache running on http://valkyrien.imada.sdu.dk:80). Tomcat is running on port 8080 and Apache virtualhost is setup like this:
ProxyPass /gcp http://127.0.0.1:8080/ nocanon
ProxyPassReverse /gcp http://127.0.0.1:8080/
ProxyPreserveHost on
The war is deployed as ROOT.war to Tomcat's /webapps/ directory.
The index page of my grails application is shown, but the links on the page along with the asset links are wrong. None of them are prefixed with /gcp/.
Example: The javascript asset for jQuery at the html file is:
<script src="/assets/jquery-8c9c0e26152ea554b3ed6c4390439134.js" type="text/javascript"></script>
Which will try to access the js file at <APACHE-URL>/assets/jquery-8c9c0e26152ea554b3ed6c4390439134.js even though the file is in fact available at <APACHE-URL>/gcp/assets/jquery-8c9c0e26152ea554b3ed6c4390439134.js. The same apply to any link to controllers and actions.
Adding any combination of the following to Config.groovy or application.properties does not change anything (as suggested by answers on StackOverflow):
grails.serverURL="http://valkyrien.imada.sdu.dk/gcp"
grails.app.context = "/gcp"
It seems like Grails ignores the serverURL properties. Any suggestions toward why this is not working?
Running without Apache is not an option.
Thanks!
Deploy your app not as ROOT.war but as gcp.war and updated properties
...or better use mod_jk for apache.

Configuring Apache HTTP server with JBoss cartridge on Openshift

I am using JBoss/Tomcat + Mysql cartridges.
I would like to serve static resources (css,js,images) using Apache and host those files outside the WAR.
I would also like to be able to use Apache to configure redirect rules etc. Is there a way to do that? Thanks
You can not edit the vhost for your application, nor access the apache configs for your application when using one of the java cartridges. An apache proxy sits in front of your application, but is not accessible by you. You would either need to run a second gear with the php cartridge and host your static assets there, or try using a third party CDN to host your static files (such as amazon s3 or cloudfront). But with just using one of the java cartridges on OpenShift Online, you can not configure it the way that you are trying to.
You can do this as below. Put images, js & Css folder in Virtualhost document root. And call tomcat with help of mod_proxy_ajp configuration listed below.
ProxyPass /images !
ProxyPass /js !
ProxyPass /css !
ProxyPass / ajp://localhost:9009/
ProxyPassReverse / ajp://localhost:9009/

Apache webserver rewrite all URL's excluding some

I'm using apache httpd v2.2 server as a frontend proxy for our actual tomcat web server which hosts the Java web application.
I want to forward all urls received by apache webserver other than those having the prefix /product to tomcat.
I've tried the following set up in httpd.conf but it' doesn't seem to work
<VirtualHost *:6111>
ServerName localhost
RewriteEngine on
RewriteRule !^(/product($|/)) http://localhost:1234/$1
Alias /product /opt/productdoc
</VirtualHost>
I tried to follow Redirect site with .htaccess but exclude one folder but was not successful
Basically all http://localhost:6111/product urls should serve from hard drive (using alias)
Any other url should be forwarded to http://localhost:1234/<original-path>
You probably want to use something like mod_jk http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html.
There are a ton of examples and tutorials and it should be pretty simple to setup and install. Now that you know the name of the connection technology, you should probably be able to find more information.
Using modjk also allows you to secure your tomcat server and keep the public off of it.

Mapping Thin - Sinatra app with apache httpd

Recently I developed a Sinatra app that running under Thin.
On my local and test servers it runs ok, but when I add it to my production env, all resources from public dir is inaccessible.
I'm not a apache guy, so I'm a little lost here.
Here is what I did:
httpd.conf
...
ProxyPass /myapp/ http://127.0.0.1:9194/myapp
ProxyPassReverse /myapp/ http://127.0.0.1:9194/myapp
By doing this, I want that every request to mydomain.com/myapp/ be forward to myapp.
In my app dir a have a public directory, with all my css, js and image files.
So, when I point to http://mydomain.com/myapp/ the html comes, but no css, images and js.
On the other hand, if I point to 127.0.0.1 at port 9194 it works as it should.
So my question is, how can I configure my apache - or thin, or sinatra - so I can have access to my public content via ProxyPass?
Thanks.
Add a / at the end of the second argument for ProxyPassReverse. The Apache docs say that if the first argument has a trailing slash, the second one also should have one.

Tomcat serving URLs wrong with mod_proxy and apache

I've set up a host with apache to serve static pages and to use Tomcat to serve my web application (See this question). The static pages are server from
"http://myhost.com"
and the dynamic (tomcat) pages are server from
"http://myhost.com/myapp"
The mod_proxy makes sure the "http://myhost.com/myapp" are forwarded to tomcat server running on "http://myhost.com:8080".
The problem is that now you get the standard Tomcat introduction page on "http://myhost.com/myapp" but if you click on a local link (e.g. 'Status') on the left, it generates an URL
"http://myhost.com/manager/status" while it should generate: "http://myhost.com/myapp/manager/status"
(The same is true for webapps installed under tomcat)
What should be changed in my configuration (apache, tomcat?) to redirect my tomcat links to the right place?
Have you set the ProxyPassReverse setting in your httpd.conf. This will overwrite the HTTP Header an you'll get to the correct request on the side of tomcat.
Your URLs are mapped from:
http://myhost.com/myapp -> http://myhost.com:8080
This means that accessing the above URL will be mapped to the ROOT application in Tomcat. The ROOT application will generate pages that contain links from Tomcat's root context.
In other words, if you go to:
http://myhost.com:8080
you will get a page that contains links to
http://myhost.com:8080/manager/status
This link will work. However when that page is given back to a browser that requested it via Apache, the full URL then looks like: http://myhost.com/manager/status
I assume that you intend to deploy an application called 'myapp' to Tomcat? If that is the case the Tomcat URL for this app will be
http://myhost.com:8080/myapp
Which will also work be mapped correctly when accessed via Apache.
If you absolutely must access Tomcats root application in this way you'll have to rewrite the URLs it outputs in the pages it returns.
I've had the most success with mod_proxy_ajp. It requires mod_proxy, but works over ajp. Using it instead, your conf file looks similar
ProxyPass / ajp://localhost:8009/
See my similar question and also the answer to this question. The only fault in mod_proxy_ajp that I've found is that if I need to restart tomcat I have to force an apache restart too.