Using apache mod_alias in vhost to link assets from external server - apache

This is an outside shot I know. I am supporting a site that has constantly changing assets that are excluded from the repository for obvious reasons. Currently I am having to FTP these assets to my local computer in order to develop and test properly. What I want to do is simply link to the assets on the server. I thought this might be possible using Apache's mod_alias, but I cant get it to work:
Alias /assets http://www.mysite.com/assets
Is this possible? Is there an alternative way of doing this?
Thanks

You can use mod_proxy to make Apache fetch resources from a remote server and then return them under that URL:
ProxyRequests Off
ProxyPass /assets http://www.mysite.com/assets
ProxyPassReverse /assets http://www.mysite.com/assets
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html

Related

Run cakephp app in apache alias

I'm trying to deploy a cakephp 3.1 app in a apache 2.4 powered server. My boss would like to place the app in a directory different of server's documentroot (DocumentRoot "/var/www/html" in my httpd.conf file), since multiple webapps will be served by this server.
Instead of virtualhosts, he would like to use aliases (host/app1, host/app2 etc). So I'm trying to configure it this way. I put an alias to my cake app (Alias "/scqa" "/opt/scqa/webroot" in my httpd.conf file) and wrote a RewriteBase (RewriteBase /scqa) to both cake's .htaccess files, but every absolute link present in my app is still pointing to apache's documentroot. In this particular case, it means my css and a big pile of not properly built links are 404ing. Is there some way I can fix it in apache configuration?
I know 2 other ways to fix it: Fix the links with cake syntax (will take me a week) or use virtualhosts. But is it possible to fix it and keep using apache alias?
Thanks in advance.
(The production env uses centos 7 64bits, just in case)
If I understood well, you are using aliases in your .htaccess files.
You should put the Alias in your server config file, because it won't work otherwise.
Syntax: Alias [URL-path] file-path|directory-path
Context: server config, virtual host, directory
From https://httpd.apache.org/docs/current/mod/mod_alias.html

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 ProxyPass doesn't work for multiple levels of path and enable proxypass for subdomains

I have two problems in setting Proxypass. I have setup the Proxypass in my Apache settings.
for example:
ProxyPass / http://www.domainname.com:8080/
ProxyPassReverse / http://www.domainname.com:8080/
I have the ROOT webapp in my tomcat to handle all the requests.
The following links work no problem:
http://www.domainname.com:8080/anypath1/anypathxxx
http://www.domainname.com:8080/anypath2/anypathxxx
but the followings to Apache do not work:
http://www.domainname.com/anypath1/anypathxxx
http://www.domainname.com/anypath2/anypathxxx
How do I fix the setting?
Another problem:
How do I setup wildcard proxypass for subdomains so that:
http://zzz.domainname.com/anypath1/anypathxxx proxypass to http://zzz.domainname.com:8080/anypath1/anypathxxx?
Thanks a lot in advance!!
I'am massively using Apache to loadbalance lots of Tomcats. I would strongly recommend mod_jk Apache Tomcat Connector for this case/job -> link. It is really easy to setup and truly stable!
Just install it from a repository, download binary (Windows) or build it from source.
Afterwards follow the quick start tutorial -> link
Also your second question (wildcards) could be solved this way.

Apache Mod-rewrite across domains?

OK, I have a site, at www.domain.com. I added a web app on heroku and it has it Heroku URL and a custom domain. However, what I'd like to do is have it accessible via those two URL but on the www.domain.com site, I'd like to access that new server via www.domain.com/customapp. I figured I could do it through URL rewrite. But all the examples I see are doing the the other way, so is my idea possible? Is mod-rewrite the way to go?
Thanks.
Why don't you try setting up a reverse proxy for www.domain.com? Assuming you are using Apache 2.2, it's pretty easy to do if you have access to the httpd.conf or httpd-vhosts.conf file.
In your case I would add the following to your httpd.conf or httpd-vhosts.conf file.
ProxyRequests Off
ProxyPass /customapp/ <URL-to-Heroku-App>
ProxyPassReverse /customapp/ <URL-to-Heroku-App>
For more information, see the docs.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse

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.