How to use the browser to access tomcat on port 8080? - java

I have a remote server, and its default port is 8080, but you know the browser default use 80 port to access it, so can not access my tomcat.
How to configure it to access the tomcat's 8080 port?
It is under the windows.
If I use www.example.com:8080 in the browser I can access the server, but if I use www.example.com I can not access it.
EDIT
I use Tomcat + IIS (Server Consolidation), IIS occupy the 80 port.

You cannot access the URL on http://www.example.com because the browser will try to make a TCP connection on port 80 while tomcat is listening to post 8080.
If you want to change the port tomcat is listening to, see this question
Another option is to use a proxy in front of your tomcat server. You can use apache web server or Nginx. They can listen to port 80 and forward your request to the tomcat server on port 8080.
Update
As mentioned in the comments below, as the post80 is already taken, adding reverse proxy cannot help. Because the reverse proxy will not be able to listen to port 80.
It is recommended to see which process is using port 80 and then a proper solution can be implemented.
Update
As IIS is listening on port 80, it is recommended to configure IIS to act as the reverse proxy.
You can follow this link to do so.

You can change tomcat connector port number.
Navigate to /tomcat-root/conf folder. Within you will find the server.xml file.
Open the server.xml and search for connector port and change it.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

Related

how to access java web application with ip address without entry the port

I'm using glassfish 4.1 server with port 8080.
my apps can access by hit localhost:8080 or using my_ip_address:8080.
now, I want access my apps only with ip address without entry the port, say my ip is 10.1.2.133, so when I hit 10.1.2.133 it's go to my apps.
how to do it?
I've tried changing the port to 80 and it worked so well. but I still want to use port 8080 instead 80.
I've tried changing the port to 80 and it worked so well. but I still want to use port 8080 instead 80.
Port 80 is the only default port that web browsers understand for the HTTP protocol.
If you want to use a different port (8080) for your server, you must either:
use port 8080 in the URL
set up another server on port 80 that will either redirect requests to port 8080, or reverse proxy the requests to port 8080.
Redirection works by having the server on port 80 send HTTP 3xx responses that tell user's the browser to resend the request to the URL for the port 8080 server.
Reverse proxying works by the server on port 80, sending the request to the port 8080 server itself, and then relaying the response.
You could consider using a reverse proxy like apache httpd or HAProxy in front your application. Configure them to listen to port 80 and redirect requests based on the context to your application at 8080
Take a look at::
https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
https://github.com/foosel/OctoPrint/wiki/Reverse-proxy-configuration-examples
https://dzone.com/articles/how-to-configure-ha-proxy-as-a-proxy-and-loadbalan
The default Http port is 80, and therefore if your app run at 80 you can omit it, in other cases you must specify the port. Else you must have a Proxy server listen at 80 and re-direct it to the required server based on context( read path ) or some-other information.
You can run another server that points to your server on 8080. Your other server would then be running on port 80 as this is the default port.
Config on Apache would be something like this:
<VirtualHost *:80>
ServerName sample.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://YOUR_IP_HERE:8080/
ProxyPassReverse / http://YOUR_IP_HERE:8080/
RewriteEngine On
<!--other config here-->
</VirtualHost>

How do i rewrite url using urlrewrite in RestExpress

I have a small REST-api using port
{ip}:8081/{crud-operations-name}
and I have a website that points to this address but the problem is i still have to put port :
8081
all the time.
Actually I could just set my Java server to run on port :
80
, but that would lead to update all my clients(mobiles app) to listen on port 80 not on 8081 (Am i correct that all http request defaults to port 80?Correct me if im wrong). So I guess a better way is to rewrite the url when it comes to the Rest-Server of mine.
What I would want is like the behavior of htaccess hiding the port, Is it possible in urlrewrite using RestExpress?
You can add a port redirect to your Tomcat's server.xml file. You can invite your users to access the site without specifying a port number, meaning that everyone will hit the default port 8080. When anyone accesses using port 8080, the request will be redirected to 8081 which port presumably has some security settings associated with it.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
enableLookups="false"
redirectPort="8081" />

Tomcat is running on 8080 port but unable to access remotely using ip address?

I have freshly installed apache-tomcat-7.0.62 on server. It starts without any error but i am unable to access it using : -
http://IP:8080/
here IP is ip address of server.
I have also run following command : -
here is the screenshot
Thanks
Find the server.xml located under confs folder of the catalina(tomcat).
Find out Connector tag which each one indicates for one connector isntance.
If the connector comes with no address attribute(as default), so tomcat will listen for all addresses. If it has address attribute, so just remove it out, or either have another Connector to listen for the related ipv4 address.
<Connector ... address="ip_v4_addr"/>
Check tomcat spec for Connectors here.
Next make sure the port is open and allowed to be invoked by any firewall, also make sure the ip-address is valid(public and reachable), and ISP doesn't block it.
Default port for tomcat(HTTP) is 8080 and 8443 for HTTPS, maybe your ISP doesn't let you workout with non-std ports, or the firewall issue.

I want to run a project from my localhost

I'm following a textbook example and I need to run Apache and then open the file in my browser as http:localhost:0000/file
How do I know which number my local host is? The textbook says 9080 but I assume that's not universal.
In the eclipse view "Servers" double click in Tomcat -> tab Overview and check the http port.
By default the port used is 8080.
In the tab modules you can check the path
by default:
http:localhost:8080/projectName
In case you are using Apache Tomcat, the port where the server is listening is defined in the server.xml file (ApacheTomcatHome/conf/server.xml) in a line more or less like this one:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
This line defines the listening port as 8080 but you can change it just modifying the port and restarting the server.
To access the file you will have to deploy a web application (.war) and place at the following location the file you want to see:
ApacheTomcatHome/webapps/applicationName/file
In case your example is talking about Apache Web server the default port where the server is installed is 80. If you place your file at var/www/ then it will be accessible at http://localhost:80/file.
If you want/need to change the port, it can be done at httpd.conf (or apache2.conf) file modifying the line where it states Listen 80.

Gets the error without port number even when it is default port in tomcat?

I have tomcat installed on my local machine. I see it in server.xml where I have below entry
<Connector executor="tomcatThreadPool"
port="${http.port}"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="${https.port}"
acceptCount="100"
maxKeepAliveRequests="15"/>
where http.port value in catalina.properties is 8080 .
But every time I try to access my application it url http://localhost/myApp I get error
could not connect to localhost but it works fine http://localhost:8080/myApp. I am not getting why it expects
the port 8080 when it is already a default port? What should I do so that I do not have to mention port?
When you write http://localhost/myApp on the Address Bar of your Browser, the request always goes to Port 80, and not Port 8080. So the default is Port 80 here. For http://localhost/myApp to work you need to install something like Apache HTTP Server.
Then you can configure it with the help of a connector like mod_jk or mod_proxy to use http://localhost/myAppi, instead of http://localhost:8080/myApp. So that what ever request comes on Port 80 can be diverted to Port 8080 automatically.
Once you will download mod_jk, simply extract the file mod_jk.so to the modules folder of your Apache HTTP Server.
Hopefully the steps written here How to Configure Apache HTTP Server with Apache Tomcat, might help you in doing that.
On a Windows platform all you have to do is changing the port number in server.xml from 8080 to 80 and you are done.
The above is not true for Unix/Linux environments. Changing the port number might work on Windows but i think it might be slightly tricky on Unix/Solaris.
Under UNIX all ports <1024 are "privileged" ports. Only root may open a privileged port. It is still possible but keep in mind that it is not as simple as changing the port number when on Unix.
There are a number of workarounds for this.
http://raibledesigns.com/rd/entry/how_to_run_tomcat_on
http://mihail.stoynov.com/2011/04/04/howto-start-tomcat-on-port-80-without-root-privileges/
http://java-notes.com/
http://www.klawitter.de/tomcat80.html

Categories

Resources