Mapping Thin - Sinatra app with apache httpd - apache

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.

Related

Apache Reverse Proxy 404 errors when resources loaded from root context path

Seeing an issue after configuring a reverse proxy in my Apache web server and having a tough time finding a solution, hoping one of you may be able to assist.
Example:
I am trying to configure a reverse proxy to map the backend application URL http://appserver/app/ to the URL https://webserver/app/ on my public domain.
I noticed that any resources located under the http://appserver/app/ path (such as /app/images) are being served properly when accessed via corresponding reverse proxy URL (https://webserver/app/images).
However, some html files are being served from the backend application server root context path (http://appserver/test.html) and the requests for these files are returning 404 errors when the application is accessed via the reverse proxy URL
When reviewing the chrome dev tools network trace, I see Apache is serving these resources from the root context of the reverse proxy URL (https://webserver/test.html), instead of the reverse proxy path (https://webserver/app/test.html), as intended.
I believe this is the expected behavior in Apache, but I am trying to find a way to rewrite the URLs to serve these resources via the reverse proxy context path https://webserver/app/ instead of the root.
Below is my current configuration and I am aware that it will not work as intended when configured this way, but I have tried just about every combination of RewriteRule and ProxyPassReverse directives I can think of, to no avail.
RewriteRule ^/app/(.*)$ http://appserver/app/$1 [P,L]
ProxyPassReverse /app/ http://appserver/app/
I have also tried the following, with no luck.
RewriteRule ^/app/(.*)$ http://appserver/$1 [P,L]
ProxyPassReverse /app/ http://appserver/
Outside of the basics, I am a bit of a noob when it comes to Apache, so I apologize if this is a dumb question, but I have looked all over to find a solution, and still haven't found one :(
Any help is appreciated!
Thanks a lot

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/

serving laravel with apache vhost

I followed instructions and added in my httpd-vhost.conf file
<VirtualHost *:80>
ServerName project-laravel-learn.my
DocumentRoot "/srv/http/project-laravel-learn.my/public/"
</VirtualHost>
also added like for other local projects, map in hosts file so that
project-laravel-learn.my goes resolves to 127.0.0.1
http (web user), has all permissions to write and read on that public
folder,
also app/storage is rw- for http,
however, when I visit project-laravel-learn.my I get page saying
Whoops, looks like something went wrong!
What might be the problem? Also how I can get more detailed error message as
this one above isn't that much useful.
Just to add, app was working fine before I moved it to /srv/http/, while developing and using php artisan serve command.
EDIT: Ok it works, I forgot to start my local web server instance, however now routing does not work, I get only homepage, but clicking on any link gives 404 object not found error!?
How to fix that?
Found solution here..
http://www.epigroove.com/blog/laravel-routes-not-working-make-sure-htaccess-is-working
I will leave it for a future reference.

rails3 : appending /app1 to apache virtual host url

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

Grails URL's with Tomcat/Apache ProxyPass

Grails tends to write out the URL for everything that uses its tags as /appName/whatever. For instance, if I use the tag:
<g:javascript library="jquery"/>
the resulting tag is
<script src="/appName/jquery/jquery.js"></script>
This causes an issue with using ProxyPass with Apache/Tomcat. All of my CSS, JS, Images and links have that /appName prefixed to them.
Is there a way to work around this with ProxyPass or possibly a way for Grails to not prefix the appName to the front of all of my URL's?
If you don't have another application running as default in your tomcat, or you don't care about replacing it, you must rename you war file to ROOT.war before deploying it. (and delete the directory ROOT if it exists)
If you have severals applications and only one tomcat server, you can use virtualhosts. One virtualhost for each application. (http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html)
If you choose the virtualhosts approach, you must use de virtualhost domain when you define ProxyPass sentences and be sure that the apache server, resolves the virtualhost domain correctly. (if not, you may need to edit he os hosts file)
Sorry about my english.
That works for me, are you trying to run the app as domain.com/ rather than domain.com/appName?
If so, then you'll probably need to specify the base or absolute parameter in the tag.