Tomcat 5.5 virtual host with appbase - java

I'm trying to create a virtualhost in Tomcat 5.5. Up till now I've created the Host entry
<Host name="www.nikoslianeris.gr" appBase="test"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="test" prefix="mydoamin_access_log." suffix=".txt"
pattern="combined" resolveHosts="false"/>
</Host>
and everything is ok with that. The problem is that when I put my app in the appbase directory nothing happens. I mean, I can see from the admin console the new virtual host bat when I type the url nothing happens. I don't know what the problem might be! I found many tutorials on the subject and did what they said but nothing happens!

just brainstorming, but have you mapped www.nikoslianeris.gr to your local machine in your hosts file or a local DNS? ie any request to that domain should result in the request being sent to your machine, then the request gets sent to tomcat, and only then does the virtual host settings above kick in.
In theory you can test if this is the case using ping or traceroute on that domain, or by telnetting to your local machine on the Tomcat port and writing a sample HTTP request and also specify the "Host:www.nikoslianeris.gr" in the HTTP header. In theory.

Related

How to do a redirect behind Nginx

My Tomcat server sits behind an Nginx reverse proxy.
I configured RemoteIpValve in Tomcat to replace hostname, port and scheme. Tomcat works on localhost:8080.
Tomcat valve (server.xml)
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
protocolHeader="x-forwarded-proto"
proxiesHeader="x-forwarded-by" />
When i redirect from https://example.com/pages/MyForm.jsp to https://example.com/pages/MyForm.jsp?message=Something, it works correctly,
but when i try to redirect from https://example.com/pages/MyForm.jsp to https://example.com/pages/AnotherPage.jsp?message=Something the
site can't be reached.
Unlike the first example request, the second one displays port 8080 in the location of Response Headers.
location: https://example.com:8080/pages/AnotherPage.jsp?message=Something`
Request Method: GET
Is there any configuration that should be done in Nginx or Tomcat? How can i solve this problem?

Prevent Improper-Input-Handling attack

I'm trying fix a site vulnerability, it is "Improper Input Handling" attack raised by WhiteHat. Let's say my website is www.mywebsite.com and there is hacker's website www.hacker.com
whenever there is a request send to www.mywebsite.com with modified "Host" header point to www.hacker.com, my site will create a redirect to www.mywebsite.com along with whatever the url it was. To fix this I tried below tomcat virtual host configuration but still it's redirecting to other website.
<Host name="defaultlocalhost" appbase="whatever">
<!-- allow addresses to these host -->
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow=".*\.mywebsite1\.com|.*\.mywebsite2\.com"/>
</Host>
So, my question is, is it the right approach to prevent this host header attack ? If yes, what I did wrong that still not working? (The ultimate goal is, if it is not the legit Host that been passed in, the request should be discard/ignored/return 404 but not redirect with 302)

Java web application hosting

I hosted my application into Tomcat server and configured server.xml so that i can access my web application by directly accessing the website name eg:www.example.com but it works only when it is followed by my port number for eg: www.example.com:8080, I am using godaddy for VPS.
This is the configuration i have used
<Host name="example.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.example.com</Alias>
<Context path="" docBase="Prototype" 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>
but it works only when it is followed by my port number for eg: www.example.com:8080
By 'works' , do you mean Tomcat starts with any port you mention in config but site can be accessed via 8080 only?
if not sure, refer to <tomcat_dir>/logs/catalina.out file to view startup logs,
it so may happen that your VPS has any other application already running on port 80 , httpd typically or NGINX in some cases, you need to stop the app and start tomcat with port 80 in config.
how to check app running on specific port
netstat -apn|grep <port_number>
or
ss -apn|grep <port_number>
in case no app are running on port 80 or any other port you've mentioned in config and tomcat boots successfully, still you are not able to access your app via outside then most likely its network access issue,
for that you need to allow INGRESS access to your desired port in local IP Tables or Godaddy VPS config panel whichever the case may be.
the issue you have mentioned looks more like a linux admin issue.
please share more details i will guide you to exact solution
All the best.
You could provide som more info about your VPS. Here I will assume you have a full VPS with root access and you can control the all network access. Apache Tomcat runs by default on port 8080. Effectively you have two options
Run the Tomcat on the port 80 as root ( I don't recommend this approach)
As #Kayaman mentiomed, install an http proxy (apache httpd, nginx,..) which would listen on port 80 and forward all requests to 8080 (search for reverse proxy)
Have fun

How to access java web application with IP address (without doing host entry)

I have deployed an java web application using apache-tomcat-7.0.5 on particular server. Server ip is for example 192.168.0.145.
Below is the host entry I have done in server.xml in the tomcat's conf directory.
> <Host name="license.med.com" debug="0" appBase="" unpackWARs="false"
> autoDeploy="false">
> <Context path="" docBase="/data/LicenseData/setup/licenseGen/WebContent/" debug="0"
> reloadable="true" crossContext="false" />
> </Host>
After starting tomcat server when I try to access web app with URL http://192.168.0.145:10880/, it shows me home page of tomcat.
After doing below host entry in hosts file :
192.168.0.145 license.med.com
when I try to access web app with URL - http://license.med.com:10880/, it shows me home page of the application.
But I would like to access the application using Ip address only. I have tried many things but not able to access the same.
If I host the same using eclipse from my local machine, I am able to access it using IP address. But same is not possible for the server where I have deployed my application.
Please help and Thanks in advance for your suggestions.
Thanks
After going lots of trail and error as per the suggestions provided here and on other I finally found below solution :
I have added tag with the I on through I want to access the Site.
Below is the tag I have added :
<Alias>192.168.0.145</Alias>
Now I can access it with below URL :
http://192.168.0.145:10880/
Thanks all for your responses!!!

Linking Apache to Tomcat with multiple domains

Okay, so I've been working for a while on this, and have been searching, but so far I have not found any answers that actually answer what I want to know. I'm a little bit at the end of my rope with this one, but I'm hoping I can figure this out sometime soon.
So I have Apache 2 installed and serving up standard webpages, but I also have that linked to a Tomcat instance for one of my domains currently supported. However, I want to add another domain to the server via Apache that points to a separate code base from the one I already have. I have been coming at this from several different angles, and I have determined that I just don't know enough about setting up these servers to really do what I want to do.
Little information on my server:
Currently running a single Tomcat5.5 instance with Apache 2, using mod_jk to connect them together.
I have a worker in workers.properties that points it's "host" field to "localhost" with the correct port my Tomcat instance, so that all works.
In my Tomcat server.xml file, I have a host defined as "localhost" that points at my webapp that I am currently serving up, with that host set as the defaultHost as well.
One thought I had was that I could add a new worker with a different host than "localhost" (i.e. host2) and then define a new host in my server.xml file called "host2" to match it, but after reading around some on the internet, It seems the "host" of the worker must point to a server, and not a hostname in the Tomcat instance, is this correct?
Again, a simple rundown of what I want:
Setup in apache/tomcat combo such that www.domain1.com points at "webapp1" and www.domain2.com points at "webapp2".
First, setup mod_jk workers for both webapps. Below a sample workers.properties:
workers.tomcat_home=/usr/local/tomcat/apache-tomcat-6.0.20
workers.java_home=/usr/lib/jvm/java-6-sun
ps=/
worker.list=worker1,worker2
worker.worker1.type=ajp13
worker.worker1.host=www.domain1.com
worker.worker1.port=8009
worker.worker2.type=ajp13
worker.worker2.host=www.domain2.com
worker.worker2.port=8009
Then, set up virtual hosts on apache:
<VirtualHost *:80>
ServerName www.domain1.com
JkMount /* worker1
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.com
JkMount /* worker2
</VirtualHost>
Make sure the server.xml contains an uncommented AJP Connector for port 8009 (matching the workers port). Like this :
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
Finally, configure the tomcat hosts. Something like this:
<Host name="www.domain1.com"
appBase="/path/to/domain1"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
<Host name="www.domain2.com"
appBase="/path/to/domain2"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
You might need to make some adaptation but it should be close to the final result.
You could also use much simpler approach with mod_proxy. Have a look at http://squirrel.pl/blog/2010/03/30/mapping-tomcat-apps-to-subdomains-with-apache/

Categories

Resources