mac high sierra tomat how to change port 8080 - macos

I installed tomcat and I executed start.sh. Tomcat started.
I checked the port 8080 with the command
lsof -i :8080
There isn't any process running in this port.
How can I know in which port is running tomcat and change this port?. I have already used the port 8080 and I need to change
EDITED
I changed the connector por to 8081
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
I checked
lsof -i :8081
There isn't any process.
How can I check the tomcat port?

You should open conf/server.xml and look for a Connector tag like:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Set the port attribute to the desired value and restart the server.

Related

How to configure tomcat for https when you already setup https in application level

There are thousands of articles on how to set up HTTPS in either tomcat or at the application level in your spring boot application. But I didn't find a way to configure tomcat for an application that already has configured HTTPS.
I've already set up my spring boot application to run on HTTPS by configuring these properties:
server.port=7070
server.ssl.enabled=true
server.ssl.key-store-password=my_password
server.ssl.key-store-type=PKCS12
server.ssl.key-store=keystore-path
server.ssl.key-alias=key_alias
And it perfectly works when I run my IDE(Intellij) and serves on https://localhost:7070 on my machine.
On the other hand, When I deploy my app into the tomcat. it runs on the port of tomcat which is defined on server.xml connector. for instance :
<Connector port="7071" protocol="HTTP/1.1" connectionTimeout="20000" />
By doing so, The connector port in tomcat overrides the port number on the application.properties.
So if I want to run my application in HTTPS in tomcat, Documents says I need to define a new connector, for example :
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
type="RSA" />
</SSLHostConfig>
</Connector>
or
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true" >
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
certificateFile="conf/localhost-rsa-cert.pem"
certificateChainFile="conf/localhost-rsa-chain.pem"
type="RSA" />
</SSLHostConfig>
</Connector>
But these ways, I have to configure my Keystore, password, alias, and ... again in my tomcat.
I'm wondering is there any other way around not configuring again my Keystore, password and .. again in tomcat?
No, there is no other way around it. server.* properties are only applied when running the application in an embedded container. When deploying to an existing Tomcat instance, they are not used.

GZIP not working for Apache tomcat

apache tomcat(8.0.36)
1.I have added .htaccess file in root then also its not working
2.I have added following code in server.xml
<Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1"
disableUploadTimeout="true"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,
text/xml,text/plain,text/javascript,text/css,application/json"/>

Apache Tomcat Error: Socket bind failed

When I run my Apache Tomcat server on Windows 8.1, the server returns:
java.lang.Exception: Socket bind failed: [730049] The requested address is not valid in its context.
at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:310)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:790)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:544)
at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:67)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:569)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:851)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
at org.apache.catalina.startup.Catalina.load(Catalina.java:600)
at org.apache.catalina.startup.Catalina.load(Catalina.java:623)
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:497)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)
Here's my Connector in my server.xml as well:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
address="192.168.0.1"/>
And my Engine:
<Engine name="Catalina" defaultHost="192.168.0.1">
And my Host:
<Host name="192.168.0.1" appBase="webapps"
unpackWARs="true" autoDeploy="true">
I should also mention that my private and public IP addresses are available.
Based on your config
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
address="192.168.0.1"/>
And given error message
Socket bind failed: [730049] The requested address is not valid in its
context.
It seems that Tomcat can't bind to IP configured address 192.168.0.1 as it is not assigned to any available interface.
Make sure that IP address is actually available by running
ipconfig /all
on Windows
or
ifconfig -a
on linux.
192.168.0.1 is almost certainly not your Tomcat host's IP address but the IP address of a router. You can't bind to a non-local IP address. Most of the time you don't need to specify this attribute at all, when it will default to 0.0.0.0 which means 'any'. About the only time you need to specify it is if you want to set it to 127.0.0.1, for a Tomcat that is only supposed to be accessed from the localhost.
Change The settings to following and you should be fine:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
N.B. If your ip is not 192.168.0.1 then the above config will not work and you will need to ifconfig <devicename e.g.eth0/wlan0> 192.168.0.1 for linux, or change ip address of windows machine accordingly vide: http://kb.mit.edu/confluence/display/istcontrib/Windows+8+-+Set+up+with+a+Static+IP+Address.

mod_jk utf-8 character set setup

I am running httpd + mod_jk + 2 tomcat servers in Ubuntu. When I submit a form in a non-Latin language I get garbage in the DB.
If I submit the same form through Tomcat directly bypassing httpd everything looks good.
following is my configuration:
/etc/apache2/conf.d/charset:
AddDefaultCharset UTF-8
tomcat1:
< Connector port="8080" protocol="AJP/1.3" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
tomcat2:
< Connector port="9080" protocol="AJP/1.3" connectionTimeout="20000" redirectPort="9443" URIEncoding="UTF-8" />
JDBC connection:
jdbc:mysql://localhost:3306/myapp?useEncoding=true&characterEncoding=UTF-8
/etc/apache2/mods-available/jk.conf (the same file I set up my loadbalancer)
JkOptions +ForwardURICompatUnparsed
Am I missing something?
Thank You!
I found my problem, I mixed up the HTTP connector with the AJP connector which was declared twice in Tomcat's server.xml . The second declaration did not even include the attribute URIEncoding.
<Connector URIEncoding="UTF-8" port="8009" protocol="AJP/1.3" connectionTimeout="10000" keepAliveTimeout="10000" redirectPort="8443"/>
work fine for me

Edit tomcats server.xml using ksh?

I'm wondering whats the easiest way to change some settings in tomcats conf/server.xml configuration file through a ksh script?
For example, I want to change the default ports on these 2 snippets:
Replace this:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
With this:
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
And,
Replace this:
<Server port="8005" shutdown="SHUTDOWN">
With this:
<Server port="8006" shutdown="SHUTDOWN">
Many thanks!
I guess you want to change this in the config? This would be a simple sed, you can make it a bit safer by adding more than just the number:
sed -i 's/8005/8006' server.xml

Resources