Is it possible to alias Glassfish requests like in Apache? - apache

I want to redirect requests to /program.fcgi? to the actual location on the filesystem which is /usr/local/.../program.fcgi?. In Apache I can add the following to the configuration file
Alias /program /usr/local/.../program
How do I do the same in Glassfish?

Glassfish lets you include a sun-web.xml in WEB-INF of your web application that allows you to provide alternate docroots
An example entry would look like :
<property name="alternatedocroot_1" value="from=*.jsp dir=path_to_directory"/>
Details here

Related

Unable to find httpd.conf

I'm running tomcat and I want to change the default webroot so that it points to another location. Is there a way to find out what's running tomcat or where the default webroot is set as I can't find httpd.conf which is where I believe it's usually set?
Cheers,
Alexei Blue.
**UPDATE:**
It's been a long time since I looked at this question that I forgot about it. In the end it turned out that we were using Apache HTTPD to accept requests from port 80. From there we had the webroot and ProxyPass rules set in the /etc/httpd/conf/virtual-hosts/default.conf file (these can also be set in /etc/httpd/conf/httpd.conf). From there we had several tomcat instances running, all hosted on different ports which are setup in apache-tomcat-x/conf/server.xml.
When I wrote this question I was trying to setup a new tomcat instance to run an application in development and was told I would need to change the webroot to access my application, which was incorrect. Instead what I needed was to include a ProxyPass rule so that when my application name was recognised in the URL, HTTPD would send the request to the correct tomcat instance to be processed.
E.g.
www.domain.com/myApplication
In /etc/httpd/conf/virtual-hosts/default.conf
ProxyPass /myApplication/ ajp://127.0.0.1:<ajp_port>/myApplication/
ProxyPassReverse /myApplication/ ajp://127.0.0.1:<ajp_port>/myApplication/
Where the ajp_port is setup in apache-tomcat-x/conf/server.xml. I needed to ensure that non of the ports conflicted with other tomcat instances so remember to check all ports i.e. Shutdown, HTTP, HTTP with SSL, AJP etc.
Tomcat doesn't use httpd.conf, that is an apache file. The location of the individual webapps are kept in their individual web.xml files, but the location of all the configs are in ../tomcat6/conf/server.xml and web.xml
Is it where the files come from you want to move, or where it compiles and executes them from?
As #Woody says, Tomcat does not use httpd.conf files: that's an Apache httpd thing (httpd is a web server, Tomcat is a Java application server).
You didn't mention what OS you are using or what package management software you are using (e.g. yum, apt, etc.) so I'll give you generic information as if you had downloaded and installed Tomcat directly from apache.org (which I usually recommend people do for a number of reasons).
Tomcat keeps its server-wide configuration in the conf/server.xml file in the Tomcat base installation directory (often called $CATALINA_BASE for convenience): here, you configure things like what types of connectors (e.g. HTTP, HTTPS, AJP, etc.) to use and which ports they should listen to, clustering configuration, session persistence, global JNDI and realm resources. There are also conf/web.xml and conf/context.xml files that define defaults for all webapps deployed on that instance of Tomcat, but it's best to leave those files alone unless you have a really good reason to modify them.
When you want to deploy a webapp (under the default configuration), all you need to do is drop a .WAR file into the $CATALINA_BASE/webapps/ directory and the webapp will be deployed into a "context path" (aka URL prefix) that matches the name of the file minus the ".WAR" suffix. So, if you have a WAR file called mygreatwebapp.war, then it will be deployed such that your clients can reach it at http://yourhost/mygreatwebapp/. There is a special name you can give a WAR file so that it has an empty context path: if you name your WAR file ROOT.war (case matters), then your webapp can be reached at http://yourhost/. (If you would rather use exploded-WAR directories instead of WAR files, everything above still applies except the directories simply don't have the .war extension).
Given your original question, it sounds like all you want to do is drop a ROOT.war file into $CATALINA_BASE/webapps (or replace the one that is already there): this will deploy whatever webapp you want into the URL space that you might call the "default webroot".
Update
If you want to change the directory where all the webapps live for a host, you can modify $CATALINA_BASE/conf/server.xml and change the <Host>'s appBase attribute to point to, say, /cfusion/main/www/. That will deploy all the WAR files and directories in /cfusion/main/www/ as separate webapps.
If you just want to serve a single webapp from an arbitrary location, you may create a deployment file under $CATALINA_BASE/conf/[EngineName]/[HostName]/[appname].xml. This is a standard file like META-INF/context.xml and contains a <Context> element except that you will have to specify a docBase which points to your webapp (e.g. /cfusion/main/www/mywebapp).

glassfish using virtual directory

I'm triing to host some files on my glassfish server.
i found this post explaining how to do this with virtual directories:
http://www.marceble.com/2009/07/virtual-directories-in-glassfish/
but this doesn't work for me
when i surf to: localhost:8080/media/test.txt
i get: HTTP Status 404: The requested resource () is not available.
screenshot of my glassfish controlpanel:
http://i77.photobucket.com/albums/j74/bertyhell/glassfish_error.png
Better is this article.
For GlassFish 3.1.x now it is glassfish-web.xml file inside your application config. If you use something like this:
from=/media/* dir=C:/
or the same inside glassfish-web.xml file:
<property name="alternatedocroot_1" value="from=/media/* dir=C:/"/>
Be sure that you created direcotry on your computer: C:/media
"from" must match directory on your computer.
So then it will be available here:
http://{hostName}:{portNumber}/myapp/media/*

Running jsp files from /srv/http using Apache HTTP server and Tomcat

I'd like run jsp files directly from /srv/http without deploying them the Tomcat-way. For example, I want to be able to create symbolic link to my webapp directory (e.g. /home/user/myapp/) in /srv/http and access some app's page through http://localhost/myapp/page.jsp.
Is this possible and how would I set this up?
NOTE: This is not for production. We have to use JSP at university and I want to be able to quickly test my pages.
Open the server.xml of your Tomcat. Assuming if your are using Tomcat 6.x+ then it would be at /tomcatDir/conf/server.xml.
Make an entry with your path
<Context path="/myapp" docBase="yourPathGoesHere" debug="0" reloadable="true" />
Restart Tomcat if already running.
What I did at the moment was creating a symlink in /var/lib/tomcatX/webapps to my project path. This is not the answer I was looking for though, but it is a way to deploy an app without much work.
(X in the above path means your Tomcat version)
If you set <Host name="localhost" appBase="/srv/http"> then all of the directories in it will be deployed as web applications.
If you want /srv/http to be the ROOT application/directory add a file: tomcat/conf/Catalina/localhost/ROOT.xml
with the Context docBase="/srv/http", rather than adding a Context definition to server.xml - this has been strongly discouraged for years.

Can we point multiple urls to the same webapp in tomcat

I am using an apache web server and a tomcat server for hosting few webapplications.
These webapplications not very different from one another and I want to consolidate all these webapplications into one webapp to minimize the process overheads.
The webapplications are currently being accessed with separate urls ex: localhost:8080/webapp1, localhost:8080/webapp2.
Without changing the urls is there a way that I can host a webapplication on tomcat say "singlewebapp" such that it will respond to both localhost:8080/webapp1 as well as localhost:8080/webapp2?
One of my team members suggested an idea on symlinks and junctions which triggered a discussion on apache tomcat's docbase feature and we found a very elegant answer to this question in it.
Let's say the webapplication is abc.war. We deploy abc.war in tomcat webapps as abc folder then we need to configure the server.xml of tomcat as follows and restart tomcat:
<Host ...>
...
<Context path="/webapp1" docBase="/abc" />
<Context path="/webapp2" docBase="/abc" />
</Host>
Believe this is very useful usage for supporting white-labelling and multi-tenancy.
I dont think you can do this in that way. Looks like your host name and ports for all the applications are same, but context roots (webapp1 and webapp2) are different. We cannot have sinlgle context root to access myltiple applications with same host name and port.
Every web server can run one application on one port and host combination. If you want to run multiple applications on the same host, obviously you need to add as many virtual IPs and should be configured in your web server .config file to make the applications accessible virtually.
We can create virtual servers on web server based on IP address ( there are software and hardware virtual server concepts which you need to study). To have multiple IP address on your single server you need add as many ethernet cards to expand the number of IPs virtually.
If you fine to use virtual server concept , offcourse you need slightly change your requirement.
Instead of editing server.xml make context.xml in local host(or your host) of catalina of tomcat. because if edit server.xml we need to restart the server.
creation of context.xml :
xml file name must be your path name i,e webapp1/webapp2
data in xml as follows (if you are creating path for abc.war file)
a). xml file name is webapp1.xml
b). xml file name is webapp2.xml
"lessthan symbol" ?xml version="1.0" encoding="UTF-8" standalone="yes"?>
"lessthan symbol" Context reloadable="true" privileged="true" docBase="${catalina.home}/abc" crossContext="true" antiResourceLocking="false" allowLinks="true"/>
above xml files must be place in tomacat/conf/Catalina//

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.