Tomcat, Httpd : Running both at same time and calling based upon URL. - java

I am working on Debian X64 where I have tomcat with multiple webapps hosted which works fine.
I have an Apache webserver running which is hosting a CMS and which I would like to open when for example www.domain-cms.com is called.
Right now, the Tomcat has 2 webapps which are called again based upon URL like www.domain-tom1.com and www.domain-tom2.com
Now my question is how to run both together and distinguish based upon URL. I have done the following changes, kindly let me know what am I missing.
Tomcat's server.xml :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat">
<Connector port="80" protocol="org.apache.coyote.http11.Http11NioProtocol" compression="force" compressionMinSize="1024"
connectionTimeout="20000" maxPostSize="5242880"
URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
keystoreFile="keystorefile" keystorePass="PASSWORD" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"/>
<Host name="domain-first.com" autoDeploy="true" unpackWARs="true" appBase="tooltank_webapps">
<Alias>www.domain-first.com</Alias>
<Context path=""/>
</Host>
<Host name="domain-second.com" autoDeploy="true" unpackWARs="true" appBase="aupair_webapps">
<Alias>www.domain-second.com</Alias>
<Context path=""/>
</Host>
<Connector port="8010" protocol="AJP/1.3" redirectPort="443" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
</Engine>
apache2.conf :
I have added this in it, but seems wrong as I want to redirect based upon URL, but don't know what to add.
<IfModule jk_module>
JkWorkersFile /etc/apache2/workers.properties
JkLogLevel INFO
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
// I think below is wrong, I want to redirect based on URL.
SetEnvIf Request_URI "/error/*" no-jk
SetEnvIf Request_URI "/blog*" no-jk
JkMount / tomcat
JkMount /* tomcat
</IfModule>
(END)
workers.properties file :
worker.list=tomcat
# Set properties for worker (ajp13)
worker.worker.type=ajp13
worker.worker.host=127.0.0.1
worker.worker.port=8010
(END)
Now whenever I try to start Apache, I get an error :
[....] Restarting web server: apache2(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
failed!
How can I connect both Apache server and tomcat and serve CMS and webapps in parallel based upon URL. Kindly let me know. Thank you. :-)

1) Port 80 usually used by httpd apache server whereas you are using it for Tomcat as I am seeing in your server.xml <Connector port="80"
2) Add virtual host in server.xml to direct different websites in Tomcat for example:
<Host name="domain-tom1.com" appBase="/var/java/apache-tomcat-7.0.47/webapps/">
<Context path="" docBase="direcory-in-webapps"/>
<Alias>www.domain-tom1.com</Alias>
</Host>
<Host name="domain-tom2.com" appBase="/var/java/apache-tomcat-7.0.47/webapps/">
<Context path="" docBase="direcory2-in-webapps"/>
<Alias>www.domain-tom2.com</Alias>
</Host>
you can write this between </hots> and </Engine>

Related

Stopping and starting a service present in server.xml using tomcat manager application/api (Single tomcat instance)

I have multiple services defined in server.xml and below is the one which i need to restart(stop and start again) using tomcat manager application/api.
<Service name="myService">
<Executor name="myExecutorPool" namePrefix="my-http-pool"
maxThreads="10" minSpareThreads="1"/>
<Connector
port="8701" protocol="org.apache.coyote.http11.Http11Nio2Protocol" SSLEnabled="true"
executor="myExecutorPool"
maxSavePostSize="-1"
scheme="https" secure="true"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100"
sslEnabledProtocols="${sslEnabledProtocolsMediumSecurity}" server=" "
allowUnsafeLegacyRenegotiation="false"
clientAuth="want"
bindOnInit="false"
URIEncoding="UTF-8"
useBodyEncodingForURI="true"
keystoreType="PKCS11"
keyAlias="server"
trustManagerClassName="com.example.com.myproj.cert.RestTrustManager"
sendReasonPhrase="true"
sslImplementationName="com.example.com.myproj.cert.MyProjImplementation"
ciphers="${tls.ciphers}"
/>
<Engine name="myEngine" defaultHost="localhost">
<Valve className="org.apache.catalina.valves.MethodsValve" methodsSupported="GET,POST,PUT,DELETE,HEAD" />
<Host name="localhost" appBase="mywebapp"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="../webapps/ROOT" >
<Valve className="org.apache.catalina.valves.RedirectValve" sendToApp="/myapp/" />
</Context>
</Host>
</Engine>
</Service>
When i do curl -username:password http://localhost:8080/manager/text/list , i don't see this above service listed. It means i assume that, this service is not running as a separate service but contained inside appserver.
So i won't be able to do something like http://localhost:8080/manager/text/reload?path=/myService.
Can you please help here, how do i stop/start (restart) this particular service using tomcat manager app?
If JMX can be used here, can you please provide any links/resources for the same mentioning how to do that?

How to start/stop an application from a webapplication running both on same tomcat

I need some help: I have two .war files running on tomcat 7, one is a webapplication, the other one is just a "normal" java application. Now I want to figure out how to start/stop the application from my webapplication. Both applications are on the same tomcat. Operation system is Ubuntu 14.04.
Thanks for your help
you can configure that in your server.xml file and put 2 services :
<Service name="app1">
<Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="app1"
unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
</Service>
<Service name="app2">
<Connector port="8082" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="app2"
unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
</Service>
Then the application will run on
app1 on http://localhost:8081
app2 on http://localhost:8082
Resource Link:
Listen Multiple Ports in Tomcat
How to run different apps on single Tomcat instance behind different ports?

Apache, Tomcat : Loadbalancing and failover configuration showing blank page.

I am working on adding load-balancing and fail-over functionality to our existing Apache tomcat setup with mod_jk. For this, I have setup 2 Tomcat instances. I have made some changes, and will be pasting them. I am not getting any errors in the log of either httpd or tomcat, and I am only seeing a blank page. What am I doing wrong?
Apache webserver config :
workers.properties :
worker.list=loadbalancer
worker.server1.port=8010
worker.server1.host=localhost
worker.server1.lbfactor=1
worker.server1.type=ajp13
worker.server2.port=8011
worker.server2.host=localhost
worker.server2.type=ajp13
worker.server2.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=server1,server2
worker.loadbalancer.sticky_session=true
worker.myworker.sticky_session_force=True
apache2.conf / httpd.conf :
Include sites-enabled/
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /etc/apache2/mod_jk.log
JkMount /* loadbalancer
sites-enabled/000-default : Only contains :
JkMountCopy On
First tomcat's server.xml :
<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000"/>
<Connector port="8010" protocol="AJP/1.3" redirectPort="8081" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
<Engine name="Catalina" defaultHost="localhost" jvmRoute="server1">
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
</Cluster>
</Engine>
2nd Tomcat's server.xml :
<Server port="8006" shutdown="SHUTDOWN">
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000"/>
<Connector port="8011" protocol="AJP/1.3" redirectPort="8080" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
<Engine name="Catalina" defaultHost="localhost" jvmRoute="server2">
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
</Cluster>
</Engine>
Even if I shut down any tomcat, all I see is a blank page. What am I doing wrong? Kindly let me know. Thanks a lot.. :-)
It's not usually worth it to specify any JkMount directives outside of a VirtualHost. You should be specific and map them to each VH.
JkMountCopy should have worked for you. I suspect that some other configuration was interfering with it.

How to deploy webservice on jboss 4.0.4 application server hosted on solaris 10 with a specific port?

I am totally new to JBOSS 4.0.4 app server and Solaris 10.
I have developed my webservice WAR file with Eclipse and need to deploy it on my remote jboss web server (version 4.0.4) hosted on Solaris (version 10) and need to assign port 8088 to it.
I mean my clients need to access my web service with: http://test.com:8088/myWebService?wsdl
How can I achieve this?
What configurations should I do in order to make it possible?
One of my friend told me that JBOSS version 4.0.4 hosts every http request with just one port number, i.e all JSPs and webservices would have same port number which is defined in /export/home/app/jboss/server/default/deploy/jbossweb-tomcat55.sar/server.xml
on my development server the server.xml looks like following:
<Server>
<Service name="jboss.web"
className="org.jboss.web.tomcat.tc5.StandardService">
<!-- A HTTP/1.1 Connector on port 8080 -->
<Connector port="8090" address="${jboss.bind.address}"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
<!-- Add this option to the connector to avoid problems with
.NET clients that don't implement HTTP/1.1 correctly
restrictedUserAgents="^.*MS Web Services Client Protocol 1.1.4322.*$"
-->
<!-- A AJP 1.3 Connector on port 8009 -->
<Connector port="8009" address="${jboss.bind.address}"
emptySessionPath="true" enableLookups="false" redirectPort="8443"
protocol="AJP/1.3"/>
<Engine name="jboss.web" defaultHost="localhost">
<Realm className="org.jboss.web.tomcat.security.JBossSecurityMgrRealm"
certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
allRolesMode="authOnly"
/>
</Host>
</Engine>
Is it right?
thanks
I find the answer i guess: Actually jboss 4.0.4 is using tomcat as it's webserver and it contains server.xml which is configurable to be listen to different ports as described in this article:
http://www.mulesoft.com/tcat/tomcat-connectors
Actually I should have defined different connector and engine element in server.xml and it is done.
As I said, I modified my server.xml as following:
<Server>
<!-- Use a custom version of StandardService that allows the
connectors to be started independent of the normal lifecycle
start to allow web apps to be deployed before starting the
connectors.
-->
<Service name="jboss.web"
className="org.jboss.web.tomcat.tc5.StandardService">
<!-- A HTTP/1.1 Connector on port 8080 -->
<Connector port="8090" address="${jboss.bind.address}"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
<!-- Add this option to the connector to avoid problems with
.NET clients that don't implement HTTP/1.1 correctly
restrictedUserAgents="^.*MS Web Services Client Protocol 1.1.4322.*$"
-->
<!-- A AJP 1.3 Connector on port 8009 -->
<Connector port="8009" address="${jboss.bind.address}"
emptySessionPath="true" enableLookups="false" redirectPort="8443"
protocol="AJP/1.3"/>
<!-- SSL/TLS Connector configuration using the admin devl guide keystore
<Connector port="8443" address="${jboss.bind.address}"
maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
scheme="https" secure="true" clientAuth="false"
keystoreFile="${jboss.server.home.dir}/conf/chap8.keystore"
keystorePass="rmi+ssl" sslProtocol = "TLS" />
-->
<Engine name="jboss.web" defaultHost="localhost">
<Realm className="org.jboss.web.tomcat.security.JBossSecurityMgrRealm"
certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
allRolesMode="authOnly"
/>
<Host name="localhost"
autoDeploy="false" deployOnStartup="false" deployXML="false">
</Host>
</Engine>
</Service>
<Service name="jboss.webservice"
className="org.jboss.web.tomcat.tc5.StandardService">
<!-- A HTTP/1.1 Connector on port 8080 -->
<Connector port="8099" address="${jboss.bind.address}"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
<Engine name="jboss.webservice" defaultHost="localhost">
<Realm className="org.jboss.web.tomcat.security.JBossSecurityMgrRealm"
certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
allRolesMode="authOnly"
/>
<Host name="localhost"
autoDeploy="false" deployOnStartup="false" deployXML="false">
<Context path="/"></Context>
</Host>
</Engine>
</Service>
</Server>
As you can see, I have added a new Service tag and named it "jboss.webservice". I think the rest of the xml code is declarative and no other explanation is needed to understand.
Anyway dont forget to kill jboss process in SOLARIS and Run it again.
I tried these commands and after jboss was up again i was able to telnet to that port. :)
#ps -ef | grep 0.0.0
//here I get the process id of jboss, assume i get 1234
#kill -9 1234
//here I kill it
#cd /export/home/app/jboss/bin
//here i go to my jboss bin directory to run it
#nohup ./run.sh &
//here jboss is run
//now telnet
# telnet myIpadd 8099
that's it.
hope it helps.

mvn tomcat:run - how do I edit server.xml?

I want to run "mvn tomcat:run" from the command line, but how can I edit the server.xml to set maxHttpHeaderSize="65536" in the connectors? Or can I configure the connectors in the pom.xml?
Cheers
Nik
The org.codehaus.mojo:tomcat-maven-plugin will let you set the path to the server.xml file in the configuration section:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<serverXml>path_to_server_xml_file</serverXml>
</configuration>
</plugin>
Unfortunately, after doing some research, I don't think there's a way to edit server.xml's connectors. mvn tomcat:run uses an embedded Tomcat.
Unless someone finds something, it seems like your best bet will be to move to the maven cargo plugin and ZIP up your own Tomcat installation with your custom server.xml.
<cargo containerId="tomcat7x" [...]>
<zipUrlInstaller
installUrl="file://tomcat-custom.zip",
installDir="target/installs"/>
[...]
</cargo>
Or something of the sort...
I have been experimenting with using the serverXml parameter for the tomcat:run goal (http://tomcat.apache.org/maven-plugin-2/tomcat6-maven-plugin/run-mojo.html#serverXml).
The following server.xml seems to run with no errors, but without a Context element it does not load the webapp. I think if I copied my Context element from src/main/webapp/META-INF/context.xml to inside the Host element, it might work just fine:
<?xml version='1.0' encoding='utf-8'?>
<Server port="-1" shutdown="SHUTDOWN">
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps">
</Host>
</Engine>
</Service>
</Server>
To run with this server, I pass the serverXml as a property on the Maven command line:
mvn -Dmaven.tomcat.serverXml=src/main/resources/server.xml tomcat:run
The goal might have to be tomcat6:run if you are using a version of the plugin that supports both Tomcat 6 and 7.
see http://docs.codehaus.org/display/CARGO/Custom+File+Configurations
i think you can do it like this and place your custom server.xml in your project:
<configuration>
<type>standalone</type>
<configfiles>
<configfile>
<file>${basedir}/src/main/resources/server.xml</file>
<todir>conf</todir>
</configfile>
</configfiles>
</configuration>
and use default cargo server.xml as a template to get property replacement:
<Server port="#cargo.rmi.port#" shutdown="SHUTDOWN" debug="#catalina.logging.level#">
<Service name="Catalina" debug="#catalina.logging.level#">
<Connector port="#cargo.servlet.port#"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
scheme="#cargo.protocol#" secure="#catalina.secure#"
debug="#catalina.logging.level#"
emptySessionPath="#catalina.connector.emptySessionPath#"
URIEncoding="#catalina.servlet.uriencoding#" />
<!-- Define an AJP 1.3 Connector on port #cargo.tomcat.ajp.port# -->
<Connector port="#cargo.tomcat.ajp.port#" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="#cargo.hostname#"
debug="#catalina.logging.level#">
<Realm className="org.apache.catalina.realm.MemoryRealm" />
<!-- Note: There seems to be a bug in Tomcat 5.x if the debug attribute
is present. Ideally we would have written:
debug="#catalina.logging.level#"
However, doing this result in a NullPointerException in
ExpandWar.java at line 145. -->
<Host name="#cargo.hostname#" appBase="webapps" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<!-- Contexts to explicitely point to where the wars are located -->
#tomcat.webapps#
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="#cargo.hostname#_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
</Host>
</Engine>
</Service>
</Server>

Categories