properly map to webapp to domain in tomcat7 - java

Somehow I cannot normally map domain to my webapp in tomcat7.
Here is the parts from server.xml:
<Engine name="Catalina" defaultHost="localhost">
<Host name="mydomain.com" appBase="webapps" autoDeploy="true" unpackWARs="true">
<Alias>www.mydomain.com</Alias>
<Context path="" docBase="myapp"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false" />
</Host>
Does the defaultHost must be localhost or mydomain.com?
I have written a script which deploys myapp in ubuntu:
#!/bin/bash
service tomcat7 stop
rm -rf /usr/share/tomcat/webapps/myapp/
cp myapp.war /usr/share/tomcat/webapps/
service tomcat7 start
After running this script I can access my app only like this: mydomain.com/myapp
If I restart tomcat then it maps to the domain ok, but there is two webapps running.
What am I doing wrong?

To make your web application the default webapp you can simply
rename your myapp.war to ROOT.war,
rm -r /usr/share/tomcat/webappas/ROOT
cp ROOT.war /usr/share/tomcat/webapps
more information available at: http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application.3F

Related

Apache Tomcat Server sub-domains

I am running apache tomcat in a remote server, I have a domain with sub-domains. I want to assign each sub-domain with a separate project. I am unable to run apache on other domain except localhost. The domain is bind to the remote server IP Address so all sub-domains refers to all projects in webapps folder not one specific.
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="https://web-dev.example.com/" appBase="web-dev.example.com"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
The name attribute of your host should contain the DNS name of the virtual host:
Usually the network name of this virtual host, as registered in your Domain Name Service server. Regardless of the case used to specify the host name, Tomcat will convert it to lower case internally.
(cf. Tomcat documentation).
Therefore you should use:
<Host name="web-dev.example.com"
appBase="web-dev.example.com">
...
</Host>
(I omitted the attributes with default values).

Tomcat and vHost fails on specific subdirectory

i try to set my domain as vhost.
My config looks like this:
<Host name="example.de" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Alias>www.example.de</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="example_access" suffix=".log"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="/opt/tomcat/webapps/app1" debug="0" reloadable="true" />
</Host>
This config works with every subdir in the webapps-directory, except for the directory I want. If I try to open the Domain, there is an empty browsertab. (Error 404) But if I call it like www.example.de/app1, the app still works and everything ist fine :/
I don't have any idea :/
PS: It's a clean setup of Tomcat, just extracted and edited the server.xml for the vHost-settings
Remember to deploy every application you'd like to appear in a virtual host, including the ROOT application. If you don't have a ROOT application, there is no "default" application that Tomcat can fall-back to, and your clients will get 404 responses when requesting /.

Unable to store cookies in war deployed from Tomcat7

I am using/trying to deploy grails war app to the tomcat7 virtual host configured in server.xml. I have modified etc/hosts to redirect www.mytest.com to localhost (referred from ramkitech). There seems no problem in the code as it works in development(By this, I mean I run my code from grails run-app and access http://localhost:8080/app/). The problem is when I deploy it to independent tomcat7 and put it as ROOT.war in the webapps folder and run the tomcat service, I can access the war based app at http://www.mytest.com:8080/ and when I try to set cookies, they do not seem to be stored and hence, I can't access the cookies set. By the way, the war was generated by the grails dev war. What could be going wrong here?
Server.xml
<Host name="www.mytest.com" appBase="webapps"
unpackWARs="true" autoDeploy="true" >
<Alias>mytest.com</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
I referred this from http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html and I am using grails cookie plugin 1.4 and basically call savePreference() with ajax providing sample cookie from the the view.
def savePreference(Map cleanParams=[:]) {
cleanParams.each{key,val->
cookieService.setCookie(key, val)
}
return "OK"
}
and here is sample cookie key value pairs I store:
prod_type:A
prod_categoryId:2
prod_id:3

How to map tomcat 7 webapp to my domain

I know this has been touched upon in several ways already, but i'm still having issues - I have a webapp in:
/var/lib/tomcat7/webapps/abc.war
I have a domain at say, my.domain.com
I've added this to my conf/server.xml (which i believe is set correctly?)
Docbase points to the war folder?
<Host name="my.domain.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/abc" debug="0" privileged="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false" />
</Host>
My domain ip is in the /etc/hosts along w/ the local host ip:
127.0.0.1 localhost
123.123.123.33 HostName.my.domaing.com HostName
$ /etc/hostnames
HostName
With my current settings above i'm am not getting any results in seeing my webapp online. Any thoughts would be very grateful!
My domain already is mapped to my /var/www/html directory too. I can see my temp index.html file online. My tomcat webapp works fine through ip:8080/abc
I'm working on Ubuntu Server 14.04 - Apache2
This is my first time working w/ tomcat and it's a bit confusing.
Thank You!
Your /etc/hosts should contain an entry like this:
123.123.123.33 my.domain.com
or
123.123.123.33 HostName.my.domaing.com HostName my.domain.com
Otherwise you won't be able to resolve the name my.domain.com to connect to your Tomcat.
If you already configured your firewall earlier, to redirect ports you type
sudo firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080 --permanent
and reboot it.

How to map domain to web application deployed on Tomcat 7 in Ubuntu?

I have a Java based web application which is deployed on Ubuntu machine. I can access the web application at localhost:8080 and it is working as expected.
Now I have domain name for the web application and I want to access web application through the browser using the domain name(http://www.xyz.com).
I want to know the steps which are required to achieve it. Before posting this question, I search over the google.
I have already added the host details in the conf/server.xml.
<Host name="xyz.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.xyz.com</Alias>
<Context path="" docBase="" debug="0" privileged="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false" />
</Host>
Also, I made changes in the /etc/hostname and added following
<IP Address> www.xyz.com xyz
What else do I need to do?

Categories