Tomcat Webapp on port 80 [duplicate] - java

This question already has answers here:
How to change the port of Tomcat from 8080 to 80?
(14 answers)
Closed 9 years ago.
I have a webapp on my tomcat server like this:
mydomain.com:8080/mywebapp
Then I connect to my webapp, and it is working correctly, but what I want is to see my webapp like this:
mydomain.com
So I don't want only tomcat on port 80, I don't want to access my webapp through its name, I want to connect directly using my domain URI.
How can I do this? I want this to work with Linux (Ubuntu 12.04 LTS) and Windows servers.

There are several ways to achieve this, but the most common way to solve it is to run Apache as a reverse proxy in front of it. You can find some details here. This will work on both Linux and Windows. For Linux, you can also use authbind to allow Tomcat to bind to port 80.
Just changing the port to 80 in your server.xml will not work in Linux, since it would require you to start Tomcat as root, which is not a very good idea.
Also, to have your webapp at /, you can deploy your war file as ROOT.war.

Running any application on a privileged port (those below 1024) requires special privileges. If you do this, you should ensure your instance is properly hardened.
To configure the port tomcat listens on you have to modify the HTTP connector in conf/server.xml (server reference documentation):
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
To change the context path of an app, you can rename the war file. To deploy it at the root, rename your war file to ROOT.war. Or you can add a META-INF/context.xml in which you can specify the desired context path (context reference docs):
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/" />

You need to set apache webserver and configure it to use tomcat.
You need to use mod_jk in order to configure apache webserver to communicate with tomcat.
Use this link to set up the mod_jk.

Related

Websockets not working on deployed Tomcat Server on Google Compute Engine

totally new to deploying apps with websockets so I feel like I'm missing something. I'm using Tomcat 8.5 on a Debian 8 instance. Steps I've done to deploy it on GCE:
Used the Click to Deploy for Tomcat.
Uploaded my .war file onto the deployed site.
Promoted the instance's IP to static.
Added firewall rule on port 80 with the target 'websocket'
Made a load balancer on the instance group of the server's instance. (Not quite sure if that helps or if I set it up right)
The load balancer looks like this.
My javascript creates the websocket like this (VDMServer is the name of the .war):
var websocket = new WebSocket("ws://[EXTERNALIP]/VDMServer/gameServerEndpoint");
And here's how I made the server endpoint class:
#ServerEndpoint("/gameServerEndpoint")
public class GameServerEndpoint {
...
}
I am able to access the website on the virtual instance's external IP and the pages of my app, but even trying Tomcat's websocket examples give the error:
Error during WebSocket handshake: Unexpected response code: 404
Also here's how my Connecter in my server.xml looks like in /var/lib/tomcat8/conf:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Also seen solution about not including the javax websocket library so I made sure not to do that. Here's what my .war's lib folder looks like. That shouldn't affect the tomcat examples though right?
Any help on this case would be much appreciated, been looking for a way to fix this all day yesterday. Thanks!
In my case it worked when I deployed a war without exporting any sources file.

Tomcat Deployment and Routing

I feel like I’m attempting to accomplish a pretty simple task but I’m stumped. I’m attempting to use the Tomcat Manage App to deploy my app and then route my root domain name to point to that deployment.
Specifically, the app currently deployed at http://www.schmud.de/home/ should load when a person types http://www.schmud.de into their browser.
I tried deploying and configuring this in CPanel with no luck. It seems that the Tomcat Manage App interface or Host Manager interface is what I’m supposed to be use to configure my routing?
My .htaccess currently looks like this:
SetHandler jakarta-servlet
SetEnv JK_WORKER_NAME ajp13
My web.xml is generated by Clojure.
There is no way to do it within the Tomcat Web Interface nor the .htaccess file. The user must have deeper access on a CPanel system.
Assuming that you have deployed your application as "app" and configured your .htaccess as I described above, here are the specific instructions I gave my root admin to solve the routing issue:
open /usr/local/easy/share/easy-tomcat7/conf/server.xml
Under the <Host> tag add this:
<Context path="" docBase=“app” debug="0" reloadable="true" />
Restart the server
Upon restart, http://domain.com/ should load my homepage (just as http://domain.com/app/ does now)

How to remove Java application name from url on Weblogic

I have a Java application deployed on Oracle Weblogic server which can be accessed via http://www.example.com/myapp
This works fine but now I want to get rid of "myapp" in the URL so the application can be accessed only via http://www.example.com
Is this possible? If yes, how?
I don't know about Weblogic but in JBoss and Tomcat you'd name your application ROOT.war.
IMHO this is not desirable so I'd employ some URL rewriting, e.g. by using an intermediate apache webserver, which then forwards /myapp(/.*) to $1.
Of course you'd have to remove the context root from any internally generated links, but how that is done would depend on your application and environment.
I deploy a Reverse Proxy, you can use Oracle HTTP Server or Apache for this, I use mod_wl_ohs in the OHS and it's pretty simple:
<VirtualHost *:80>
ServerName myexample.com
<IfModule weblogic_module>
DynamicServerList On
WebLogicHost <IP of the weblogic>
WebLogicPort <PORT>
<Location />
RedirectMatch ^/$ /store
SetHandler weblogic-handler
WebLogicHost <IP of the weblogic>
WebLogicPort <PORT>
</Location>
</IfModule>
</VirtualHost>
Plus, it'll give you another security layer if you setup and URL-Firewall using REWRITE mod.
<context-root> in application.xml needs to be set to / like this:
<web>
<web-uri>web.war</web-uri>
<context-root>/</context-root>
</web>
Further reading:
Weblogic Docs on context-root
Similar question on SO

Map different url to same web application in Tomcat

I am not clear on the following:
If we have a web application named: SomeWebApp under Tomcat's webapp directory, the url to access it is:
http://localhost:8080/SomeWebApp
My question is, is it possible to configure Tomcat so that other URLs would point to that web application?
E.g.
http://localhost:8080/ADifferentApp will also point to the SomeWebApp?
From the web.xml I think is not possible since it is about the url patterns when you are inside the SomeWebApp scope.
So what is the proper way to do it? If it is possible that is.
The approach I found to work best is to install Apache2 on the server and proxy all requests. Tomcat is surprisingly difficult to configure in other ways than intended. In my experience, Tomcat doesn't provide this functionality declaratively.
I'd rather recommend Nginx than Apache as proxy. I'm recently working on a project that incorporates tomcat and nginx works as proxy.
Once you've got nginx you can acctualy map as many url's to access the same web application as you want.
Yes,its possible to map different context path to single application edit conf/server.xml file
> **> <Context docBase="D:\Servers\apache-tomcat-7\webapps\SomeWebApp"
> > path="/SomeWebApp" />
> > <Context docBase="D:\Servers\apache-tomcat-7\webapps\SomeWebApp" path="/ADifferentApp "/>**
Access application with 2 URL's

Two different languages PHP and Java on same application with PHP on Apache and Java on Tomcat

I am also finding tough to categorize this question. So please bear with me to explain the issue.
We have two different applications:
PHP on XAMPP and
Java on Tomcat
Now we have a business case to merge both the products. ie., PHP product should be looking no different from the Java application and also it should be part of Java app. (appears in the one of the tab in Java app)
The CSS part can be taken care. But the complex part is how to collate these two application?
Also we are using Tomcat for Java and Apache for PHP,
in such case how do we bundle the product as one.
I tried googling, but most of them point to having apache and tomcat connector etc.
But I am still not clear on how to achieve this seamless integration.
Misc Info:
--- Java App: DB: MySQL, Maven, Servlet, Spring, Struts, Hibernate
--- PHP App: XAMPP (or somecases LAMP)
Please let me know if I had missed out any details.
The two applications served via apache should not be a problem look at mod_jk This will mean your java web app is still running on tomcat which it has to do anyway.
Maybe this tutorial will help. Though I haven't tried it myself so I can't say for sure.
I am able to get Apache talk to Tomcat through mod_proxy.
I actually referred to the below links to get this working (mostly changes to httpd.conf in Apache and server.xml in Tomcat):
http://tomcat.apache.org/tomcat-5.5-doc/proxy-howto.html
http://confluence.atlassian.com/display/DOC/Using+Apache+with+mod_proxy
http://publib.boulder.ibm.com/infocenter/cqhelp/v7r0m0/index.jsp?topic=/com.ibm.rational.clearquest.webadmin.doc/rwp/t_config_mod_proxy_support.htm
I then configured PHP with Apache following [this link][1] and got the PHP configured with Apache.
So as a test program, I am able to reach servlet programs (Tomcat) from a Apache like http://localhost/example/servlet then access PHP programs too with a URL like http://localhost/phptest
ZeissS, Paul and Vincent. Thanks all for your help. Even though I have a long way to go, this looks like the starting point.
=== httpd.conf in Apache server ===
# enable the below or add new
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
# Start Modules for PHP
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "c:/windows"
# Just at the end of 'Main' server configuration - add the below
ProxyRequests On
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /examples http://localhost:8080/examples/
ProxyPass /servlets http://localhost:8080/examples/servlets/
ProxyPass /jsp http://localhost:8080/examples/jsp/
ProxyPassReverse /examples http://localhost:8080/examples/
# Finish Modules for PHP
=== server.xml in Tomcat ===
<!-- searched the below connector port=8080 and I replaced that tag with the below -->
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
proxyName="http://localhost" proxyPort="80"/>

Categories