aspose file tools*
The moose likes Tomcat and the fly likes how to remove the port number in URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "how to remove the port number in URL" Watch "how to remove the port number in URL" New topic
Author

how to remove the port number in URL

Yegappan Balasubramanian
Greenhorn

Joined: Nov 19, 2001
Posts: 13
Hi all,
I am using Tomcat 4.0 server to run my JSP application.When i tried to run the application,i have to give the URL like this
http://www.mysite.com:8080/myfolder/myfile.jsp
but actually i want the URL to be given like this
http://www.mysite.com/myfolder/myfile.jsp
Also i dont want to give that http in the URL.
I would like to give the URL like this
www.mysite.com/myfolder/myfile.jsp
Any solution for the above???
Thanks
Yeg
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Well, to change the port that Tomcat uses is a simple matter of changing the entry in the server.xml file under conf directory.
For Tomcat 4.0.X the entry looks like

And in Tomcat 3.2.X

In both cases change the port to 80 and you remove the requirement to provide a port on the url string.
This should also eliminate the need for http:// but, that's a function of the browser. Most browsers use the default port of 80 and that the protocol is http. When you specify a port, it needs to know what protocol you want to use so, requires that you add http://.
Note, this is if you are only using Tomcat as the webserver. If it's used in conjunction with Apache, IIS or any other server, the process is completely different.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
allen loire
Greenhorn

Joined: Jul 29, 2004
Posts: 2
hi

i'm a tomcat newbie, and im having the same problem in removing the port number on the URL.

im running tomcat 5.0.19 over redhat linux 9.

i want to remove the port number 8443 in the url, example:

https://localhost:8443/sample/index.html to https://localhost/sample/index.html

i tried changing port 8443 to port 443 in server.xml but when i tried accessing my resource, i ended up to a blank webpage. when i returned their previous values i can access them again.

please help, im under a deadline thanks!
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

why are you accessing it with a port number at all?

Tomcat can be configured to respond to HTTP requests on port 80. That much you have probably done already. That HTTP connector has a configuration parameter named 'redirectPort' which is 8443. This is the port it will redirect SSL traffic to.

So something needs to be responding on 8443, which is why you need to uncomment the SSL connector, make sure *its* port is 8443, and also follow the other directions in the 'howto' comment in server.xml. Which you've also probably already done, since you seem able to get localhost:8443 to work.

I'm just posting this to confirm that you've done these things, because you "ought" to be able to remove the port number with these settings.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Hmm... do you have a "security restraint" ?

check the entry for 'redirectPort' on this page:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/http.html

It will only redirect to https if you have a matching <security-restraint> element (in web.xml?)
allen loire
Greenhorn

Joined: Jul 29, 2004
Posts: 2
thanks for the reply mike!

i've tried naming all the redirectPorts in server.xml to 443 instead of the 8443 default. i have learned that 443 is considered as a "universal" secured port so when you access the site, the browser does not anymore display the port number.

its good, though our company has another concern: since 443 is known as "universal" it can be the target of all hacks. we need to name a port other than 443 that we may consider "secure" but wont appear to the address bar, so any hacker wont have a clear target to hack.

im open with some ideas using jsp's too. any help will do. thanks!
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

That's an impossible requirement.

The reason that your browser switches to '443' for SSL, without you having to type :443 at the end of the URL, is precisely because it is "universally known".

Being worried that this leaves you open to attack, is like being worried that port 80 is "universally known" to be the http port, and so you should try to somehow run on port 85, while magically having browsers read the minds of your managers, and know to try 85, instead of that other 'well known and therefore unsecure' port.

So... you can get this to work on 443? (with no port showing on the address bar?) If so, this is what you really do want. Cajole your managers.
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi,

I have the same problem and i have tomcat 6.0.


This is my current server.xml configretion.

<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />


This is my host configuration
<Host name="www.myapp.com" appBase="webapps/myapp"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="."/>
<Alias>myapp.com</Alias>
</Host>

if i access my application like : http://myapp.com:8080 it's loading fine. But i want to access my page like this http://myapp.com.

Could you please help on this?


Kind Regards
S.Saravanan
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

When you don't specify a port in a URL, browsers will use the default port - 80. There are a few ways to get your Tomcat to work for port 80:
1) Change the Tomcat configuration to use port 80 instead of port 8080.
2) Use Apache HTTPD (or IIS) in combination with mod_jk. The response comes into Apache HTTPD which then uses the mod_jk module to communicate with Tomcat's port 8009. Through this port the responses are sent back to Apache HTTPD which then sends the response back to the browser.

There are quite good instructions on the second solution on Apache Tomcat's own website.



You've already tried to use the first solution. However, that would mean that your web server should not respond for port 8080. That leaves two possibilities:
1) You didn't restart Tomcat after making these changes.
2) You have two connectors, one for port 8080 and one for port 80, and the first one is blocking the second one from being active.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

You might have to use 'authbind'.

For example, in order for me to bind Tomcat7 to a port below 1024 in Ubuntu I was required to enable 'authbind'.

In ubuntu you can do this in /etc/default/tomcat7

You need to set 'AUTHBIND=yes'


OCA7
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi Rob Spoor,

Thanks for your quick response. After made change, i have restarted my tomcat. But no luck.

This is my current server.xml.




Kind Regards
S.Saravanan
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi Louis Bros,

I have windows XP. Could you please explain, how to setup AUTHBIND=yes in windows environment?.

Kind Regards
S.Saravanan
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

There are only three big differences between your server.xml and mine:
1) I have an explicit Executor. You don't need that though.
2) I have "localhost" as the Host name.
3) I have "webapps" as the appBase.

The latter is the one I think is the oddest. The appBase should be the base directory of all web applications. Yours seems to be the base directory of only one web application. Perhaps this is causing the problems.
Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

Hi, I don't use windows but after googling a bit, it seems windows doesn't require the authbind solution sorry.
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi Rob Spoor,

Thanks for your quick response. I am new to Tomcat server. If i change appBase to webapps, then how to configure my apps to this URL. Because i have more than one application under webapps directory. Or if i have only one application under webapps,will it work?




Kind Regards
S.Saravanan
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

In your webapps folder there should now be one folder for each web application. For instance, if you have folder webapps\myapp then you can access this through http://www.myapp.subdomain.com/myapp. There is also one folder called ROOT which you can use as the root: http://www.myapp.subdomain.com/.
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi Rob Spoor,

Thanks for your response.


For instance, if you have folder webapps\myapp then you can access this through http://www.myapp.subdomain.com/myapp. - For this case, i can access myapp through http://www.myapp.subdomain.com:8080/myapp instead of http://www.myapp.subdomain.com/myapp. That means still i need to type port 8080 in the URL

There is also one folder called ROOT which you can use as the root: http://www.myapp.subdomain.com/.. For this case shall i need to put my myapp under ROOT folder?


Kind Regards
S.Saravanan
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Its contents, yes. You basically rename your application folder to ROOT.
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi Rob Spoor,

Thanks for your response.

After rename my myapp folder into ROOT,

If i access the page like : http://www.myapp.subdomain.com nothing is loaded.
If i access the page like : http://www.myapp.subdomain.com:8080, it's loaded my apps properly.

So it means still the port 8080, i need to give in the URL, other wist it won't work.

Is something wrong with DSN Record creation?

Kind Regards
S.Saravanan
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

DSN record? Do you perhaps mean DNS? If so, then you could try by pinging the domain name and see what IP address shows up.

If Tomcat's still working on port 8080, you've specified that Tomcat should run on port 80, and you've restarted Tomcat, that could mean that you are perhaps connecting to some other Tomcat instance, or perhaps another connector inside the existing Tomcat. Do you have two connectors?
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi Rob Spoor,

Thanks for your response.

If i have the following configuration in my server.xml file. Then i can access my application using this link http://www.myapp.subdomain.com:8080




If i change the following configuration in my server.xml file after server rstart. Then using this link http://www.myapp.subdomain.com nothing is loaded




Kind Regards
S.Saravanan


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Check your log files. Perhaps Tomcat can't start on port 80 because some other application (Apache, IIS) is using the port.
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi Rob Spoor,

Thanks for your response.


After change the port into 80 while server restart i got the following logs.



It seems server started properly.






Kind Regards
S.Saravanan
saravanan saminathan
Greenhorn

Joined: Apr 19, 2007
Posts: 19
Hi Rob Spoor,

Do i need to setup something like mod_proxy in appache server?. Or is it possible with Tomcat 6.0 server configuration itself?.


Kind Regards
S.Saravanan
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Tomcat itself should be able to run on port 80. I just don't know why it doesn't work. mod_jk (rather than mod_proxy) can be used, but it adds another layer that should not be necessary. mod_jk should only be used to incorporate JSP files and servlets in an already existing Apache installation, or to load balance two or more Tomcat instances.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to remove the port number in URL