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

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.

Related

Window 10 Getting tomcat 9 to work on https

My goal is to use javascript webkitGetUserMedia to access the webcam and use java WebSocket on my LAN Network. I using apache-tomcat-9.0.20 with apache-maven-3.6.3 and eclipse ide. I am able to access the http on my network just fine. However, with https I'm only able to access on the server itself. I have tried turning off my firewall changing the default host name to the server computer name. But nothing see to work. Please remember the webcam needs https to be use and I was able to use my code in my web with apache service by only change jsp to php so I really doubt it a firewall issue.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
--><Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<!-- A "Connector" using the shared thread pool-->
<Connector connectionTimeout="20000" executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation. The default
SSLImplementation will depend on the presence of the APR/native
library and the useOpenSSL attribute of the
AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of
the SSLImplementation selected. JSSE style configuration is used below.
-->
<Connector SSLEnabled="true" maxThreads="150" port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol">
</Connector>
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
This connector uses the APR/native implementation which always uses
OpenSSL for TLS.
Either JSSE or OpenSSL style configuration may be used. OpenSSL style
configuration is used below.
-->
<Connector SSLEnabled="true" maxThreads="150" port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol">
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol"/>
<SSLHostConfig>
<Certificate certificateChainFile="C:\Users\spjpi\Desktop\localhost.pkipath" certificateFile="C:\Users\spjpi\Desktop\localhost.cer" certificateKeyFile="C:\Users\spjpi\Desktop\localhost.pem" type="RSA"/>
</SSLHostConfig>
</Connector>
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine defaultHost="localhost" name="Catalina">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>
<Context docBase="camera" path="/camera" reloadable="true" source="org.eclipse.jst.j2ee.server:camera"/></Host>
</Engine>
</Service>
</Server>
First, in your sample configuration you are registering multiple times same ports (2x8080 and 2x8443), so your server will be throwing errors in your console.
Make sure to register only one connector for every port. In another way, you will be getting an exeption like this:
27-Feb-2020 01:56:22.744 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]<br>
27-Feb-2020 01:56:22.783 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]<br>
27-Feb-2020 01:56:22.795 SEVERE [main] org.apache.catalina.util.LifecycleBase.handleSubClassException Failed to initialize component [Connector[HTTP/1.1-8080]]<br>
org.apache.catalina.LifecycleException: Protocol handler initialization failed
at org.apache.catalina.connector.Connector.initInternal(Connector.java:983)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:533)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:1059)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.startup.Catalina.load(Catalina.java:584)
at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
Caused by: java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:248)
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:222)
at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1119)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1132)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:557)
at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:74)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:980)<br>
... 13 more
So, you should select one of this configuration for port 8080:
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<!-- A "Connector" using the shared thread pool-->
<!--<Connector connectionTimeout="20000" executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>-->
Or With a shared thread pool:
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<!--<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>-->
<!-- A "Connector" using the shared thread pool-->
<Connector connectionTimeout="20000" executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
Similar case, with your SSL port 8443:
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 This connector uses
the NIO implementation. The default SSLImplementation will depend on the
presence of the APR/native library and the useOpenSSL attribute of the AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of the
SSLImplementation selected. JSSE style configuration is used below. -->
<Connector SSLEnabled="true" maxThreads="150" port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol">
<SSLHostConfig>
<Certificate
certificateChainFile="C:\Users\spjpi\Desktop\localhost.pkipath"
certificateFile="C:\Users\spjpi\Desktop\localhost.cer"
certificateKeyFile="C:\Users\spjpi\Desktop\localhost.pem"
type="RSA" />
</SSLHostConfig>
</Connector>
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2 This
connector uses the APR/native implementation which always uses OpenSSL for
TLS. Either JSSE or OpenSSL style configuration may be used. OpenSSL style
configuration is used below. -->
<!--<Connector SSLEnabled="true" maxThreads="150" port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol">
<UpgradeProtocol
className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate
certificateChainFile="C:\Users\spjpi\Desktop\localhost.pkipath"
certificateFile="C:\Users\spjpi\Desktop\localhost.cer"
certificateKeyFile="C:\Users\spjpi\Desktop\localhost.pem"
type="RSA" />
</SSLHostConfig>
</Connector>-->
With Http/2 protocol:
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 This connector uses
the NIO implementation. The default SSLImplementation will depend on the
presence of the APR/native library and the useOpenSSL attribute of the AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of the
SSLImplementation selected. JSSE style configuration is used below. -->
<!--<Connector SSLEnabled="true" maxThreads="150" port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol">
<SSLHostConfig>
<Certificate
certificateChainFile="C:\Users\spjpi\Desktop\localhost.pkipath"
certificateFile="C:\Users\spjpi\Desktop\localhost.cer"
certificateKeyFile="C:\Users\spjpi\Desktop\localhost.pem"
type="RSA" />
</SSLHostConfig>
</Connector>-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2 This
connector uses the APR/native implementation which always uses OpenSSL for
TLS. Either JSSE or OpenSSL style configuration may be used. OpenSSL style
configuration is used below. -->
<Connector SSLEnabled="true" maxThreads="150" port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol">
<UpgradeProtocol
className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate
certificateChainFile="C:\Users\spjpi\Desktop\localhost.pkipath"
certificateFile="C:\Users\spjpi\Desktop\localhost.cer"
certificateKeyFile="C:\Users\spjpi\Desktop\localhost.pem"
type="RSA" />
</SSLHostConfig>
</Connector>
A valid sample configuration (with my own keystore) could be:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="/Users/myuser/dev/keystore/keystore-dev.jks"
certificateKeyAlias="localhost" certificateKeystorePassword="localhost"
type="RSA" />
</SSLHostConfig>
</Connector>
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<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>
</Engine>
</Service>
</Server>
If everything is configured ok, start your server and you will see in your logs something like this:
27-Feb-2020 02:15:14.234 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
27-Feb-2020 02:15:14.268 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["https-jsse-nio-8443"]
27-Feb-2020 02:15:14.473 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
27-Feb-2020 02:15:14.475 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [828] milliseconds
27-Feb-2020 02:15:14.500 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
27-Feb-2020 02:15:14.500 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.20]
....
27-Feb-2020 02:15:15.144 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
27-Feb-2020 02:15:15.158 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["https-jsse-nio-8443"]
27-Feb-2020 02:15:15.164 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
27-Feb-2020 02:15:15.166 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [690] milliseconds
After that, test your server locally from a browser or command line (with curl, wget, etc):
https://localhost:8443/
https://127.0.0.1:8443/
https://YOUR_IP:8443/ (where YOUR_IP is your server IP, e.g. 192.168.0.1)
If your certificate is a self-signed certificate (for develop use) or is not signed by a trusted authority, you will get an error in your browser like this: "Your connection is not private" (e.g. ERR_CERT_AUTHORITY_INVALID).
So you need to put your certificate in the trusted certificate store, accept to follow with your unsecure-certificate, or use a production ready certificate signed by a trusted authority (for more information about this: solve invalid SSL/TLS issue).
Bear in mind that by default the tomcat connector will listen all local server addresses.
For your information, if you want to restrict the binding IP addresses, the connector has an
'address' attribute that you can specify with the IP.
From Tomcat reference: docs
address
For servers with more than one IP address, this attribute specifies
which address will be used for listening on the specified port. By
default, the connector will listen all local addresses. Unless the JVM
is configured otherwise using system properties, the Java based
connectors (NIO, NIO2) will listen on both IPv4 and IPv6 addresses
when configured with either 0.0.0.0 or ::. The APR/native connector
will only listen on IPv4 addresses if configured with 0.0.0.0 and will
listen on IPv6 addresses (and optionally IPv4 addresses depending on
the setting of ipv6onlyv6) if configured with ::.
If you can't access to your server locally with this urls provided, please provide your logs and error message.
Otherwise, if you are success accessing all this urls locally, try from a remote host:
Check that server IP is accessible from remote terminal (e.g. ping)
Try to access https://YOUR_IP:8443/ (and http://YOUR_IP:8080/) in a browser
If you receive an error message "Your connection is not private", press to see more details and accept to proceed unsafe. In this case, as commented before, check that your certificate is valid/not expired and the authority is in your trusted certificates.
If you get another kind of error, check that your server and your remote client/pc has disabled firewall rules (both side) and check remote port access with telnet.
Check your /etc/hosts and iptables configuration.
If the problem persist, provide more info please.
Hope it helps,

Fronting Tomcat with Apache HTTP Server

Apache Tomcat server.xml:
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" address="127.0.0.1" enableLookups="false" protocol="AJP/1.3" redirectPort="8443" />
Apache Http Server httpd.conf :
cd /path/to/apache/config
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
ProxyRequests Off
<Proxy *>
Order deny,allow
Deny from all
Allow from localhost
</Proxy>
ProxyPass / ajp://127.0.0.1:8009/ retry=0
ProxyPassReverse / ajp://127.0.0.1:8009/ retry=0
When i do http://[ip]/[app_name] i have this error:
Forbidden
You don't have permission to access /[app_name] on this server.
Why ?
Your configuration states
<Proxy *>
Order deny,allow
Deny from all
Allow from localhost
</Proxy>
Guess the meaning of Deny and Allow. Your configuration should work if you are coming from the same server and use localhost as your address. Careful if you use the IP address: Often localhost is no longer mapped to 127.0.0.1, but to ::1, its IPV6 equivalent.
Edit: Remove this block and try if it works then.
Note that Stackoverflow is for programming related questions, this is rather server administration, so it might be better on https://serverfault.com/ - I'm voting to transfer it over to that site. There people might be able to go further - e.g. give hints to not open up a reverse proxy for everybody everywhere on the internet.

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

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>

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