LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-17-2024, 06:19 AM   #1
sag2662
Member
 
Registered: Sep 2022
Posts: 67

Rep: Reputation: 0
apache tomcat webserver


Hi all,

I wanted to redirect url from https://example.com to https://www.servercom:7777 and for this i modified the server.xml as below in tomcat config, and the below configuration doesnot seems to work. Does anyone has ideas. Please suggest.
The url alone https://www.servercom:7777/ already works. But just redirection from the old to one doesnot. Its centos linux system

Code:
<Host name="example.com" appBase="app" unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="example" />
    <Alias>example.com</Alias>
    <!-- Add RewriteValve and RewriteRule here -->
    <Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
    <Engine name="Catalina" defaultHost="localhost">
        <Host name="example.com" appBase="app" unpackWARs="true" autoDeploy="true">
            <Context path="" docBase="example" />
            <Alias>example.com</Alias>
            <Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
            <Engine name="Catalina" defaultHost="localhost">
                <Host name="example.com" appBase="app" unpackWARs="true" autoDeploy="true">
                    <Context path="" docBase="example" />
                    <Alias>example.com</Alias>  
                    <!-- Rewrite rule to redirect to www.servercom:8080/example -->
                    <RewriteCond %{HTTP_HOST} example\.com [NC]
                    <RewriteRule ^/(.*)$ https://www.servercom:7777/example/$1 [R=301,L]
                </Host>
            </Engine>
        </Host>
    </Engine>
</Host>

Last edited by sag2662; 04-18-2024 at 02:38 AM.
 
Old 04-18-2024, 02:18 AM   #2
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
Due to your query I tried installing httpd using cygwin at my localhost Windows 11
After installation I performed following changes:
Code:
$ /usr/bin/grep "^Listen"  /etc/httpd/conf/httpd.conf
Listen 127.0.0.1:7777
Code:
$ /usr/bin/cat  startapache.sh
#!/bin/bash
if [[ -f /usr/sbin/httpd.exe ]]
then
        /cygdrive/c/WINDOWS/system32/sc.exe query mycygapachectl >/dev/null 2>&1
        Ret=$?
        if [ 0 -ne $Ret ]
        then
                echo "/usr/bin/cygrunsrv.exe -I mycygapachectl -p /usr/sbin/httpd.exe"
                /usr/bin/cygrunsrv.exe -I mycygapachectl -p /usr/sbin/httpd.exe
        fi
        while [ 1 ]
        do
                /usr/bin/ps -eaf 2>&1 |\
                /usr/bin/grep httpd 2>&1 |\
                /usr/bin/grep -E -v "^$" >/dev/null 2>&1
                Ret=$?
                if [ 0 -ne $Ret ]
                then
                        /cygdrive/c/WINDOWS/system32/sc.exe start mycygapachectl
                else
                        break
                fi
                echo "/usr/bin/sleep 5"
                /usr/bin/sleep 5
        done
else
        echo "Install httpd using cygwin setup-x86_64.exe"
fi
Before viewing my query I was having my personal website files at
C:\Users\MURUGE~1\DOCUME~1\MYWEBS~1\WebSite1
After viewing your query I have moved all files from above directory to:
/srv/www/htdocs
directory at windows
%cygwindir%\srv\www\htdocs
It is working fine for me
Code:
$ /cygdrive/c/WINDOWS/system32/NETSTAT.EXE -nato | grep 7777
  TCP    127.0.0.1:7777         0.0.0.0:0              LISTENING       8776     InHost
 
Old 04-18-2024, 02:37 AM   #3
sag2662
Member
 
Registered: Sep 2022
Posts: 67

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by murugesandins View Post
Due to your query I tried installing httpd using cygwin at my localhost Windows 11
After installation I performed following changes:
Code:
$ /usr/bin/grep "^Listen"  /etc/httpd/conf/httpd.conf
Listen 127.0.0.1:7777
Code:
$ /usr/bin/cat  startapache.sh
#!/bin/bash
if [[ -f /usr/sbin/httpd.exe ]]
then
        /cygdrive/c/WINDOWS/system32/sc.exe query mycygapachectl >/dev/null 2>&1
        Ret=$?
        if [ 0 -ne $Ret ]
        then
                echo "/usr/bin/cygrunsrv.exe -I mycygapachectl -p /usr/sbin/httpd.exe"
                /usr/bin/cygrunsrv.exe -I mycygapachectl -p /usr/sbin/httpd.exe
        fi
        while [ 1 ]
        do
                /usr/bin/ps -eaf 2>&1 |\
                /usr/bin/grep httpd 2>&1 |\
                /usr/bin/grep -E -v "^$" >/dev/null 2>&1
                Ret=$?
                if [ 0 -ne $Ret ]
                then
                        /cygdrive/c/WINDOWS/system32/sc.exe start mycygapachectl
                else
                        break
                fi
                echo "/usr/bin/sleep 5"
                /usr/bin/sleep 5
        done
else
        echo "Install httpd using cygwin setup-x86_64.exe"
fi
Before viewing my query I was having my personal website files at
C:\Users\MURUGE~1\DOCUME~1\MYWEBS~1\WebSite1
After viewing your query I have moved all files from above directory to:
/srv/www/htdocs
directory at windows
%cygwindir%\srv\www\htdocs
It is working fine for me
Code:
$ /cygdrive/c/WINDOWS/system32/NETSTAT.EXE -nato | grep 7777
  TCP    127.0.0.1:7777         0.0.0.0:0              LISTENING       8776     InHost

Hi its not apache, Its tomcat webserver also I am not using Windows. Its linux server.

Last edited by sag2662; 04-23-2024 at 09:07 AM.
 
Old 04-18-2024, 09:34 AM   #4
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
I can understand this.
Since I do not have Linux, I was trying to reproduce the same at Windows 11
Today installed apache tomcat at windows 11
Command using cygwin (bash.exe)
Code:
$ grep 7777 ../conf/server.xml
         Define a non-SSL/TLS HTTP/1.1 Connector on port 7777
    <Connector port="7777" protocol="HTTP/1.1"
$ netstat -nato | grep -E "8005|8080|8443|8443|8009|7777"
$ . ./setclasspath.sh
$ echo $JAVA_HOME
/home/murugesandins/jira/jdk-11.0.9
$ /home/murugesandins/jira/jdk-11.0.9/bin/java.exe -version
java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)
$ ./startup.sh
exec ./catalina.sh start
Using CATALINA_BASE:   C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19
Using CATALINA_HOME:   C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19
Using CATALINA_TMPDIR: C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\temp
Using JRE_HOME:        C:\Users\murugesandins\cygwin\home\murugesandins\jira\jdk-11.0.9
Using CLASSPATH:       C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\bin\bootstrap.jar;C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\bin\tomcat-juli.jar
Using CATALINA_OPTS:
eval "/cygdrive/c/PROGRA~2/Jdk17/bin/java.exe" "-Djava.util.logging.config.file=C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19/conf/logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager  -Djdk.tls.ephemeralDHKeySize=2048 -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED  -classpath "C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\bin\bootstrap.jar;C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\bin\tomcat-juli.jar" -Dcatalina.base="C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19" -Dcatalina.home="C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19" -Djava.io.tmpdir="C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\temp" org.apache.catalina.startup.Bootstrap start
Tomcat started.
$ ps -eaf | grep java
murugesa    2449       1 pty0     20:02:13 /cygdrive/c/Program Files (x86)/Jdk17/bin/java
$ tasklist | grep java
java.exe                      9064 Services                   0    105,352 K
http://127.0.0.1:7777/
at browser is working fine.
Hence you need to set related port number at server.xml file at your OS

Last edited by murugesandins; 04-23-2024 at 06:48 PM. Reason: Removed quote
 
Old 04-22-2024, 06:56 AM   #5
sag2662
Member
 
Registered: Sep 2022
Posts: 67

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by murugesandins View Post
I can understand this.
Since I do not have Linux, I was trying to reproduce the same at Windows 11
Today installed apache tomcat at windows 11
Command using cygwin (bash.exe)
Code:
$ grep 7777 ../conf/server.xml
         Define a non-SSL/TLS HTTP/1.1 Connector on port 7777
    <Connector port="7777" protocol="HTTP/1.1"
$ netstat -nato | grep -E "8005|8080|8443|8443|8009|7777"
$ . ./setclasspath.sh
$ echo $JAVA_HOME
/home/murugesandins/jira/jdk-11.0.9
$ /home/murugesandins/jira/jdk-11.0.9/bin/java.exe -version
java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)
$ ./startup.sh
exec ./catalina.sh start
Using CATALINA_BASE:   C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19
Using CATALINA_HOME:   C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19
Using CATALINA_TMPDIR: C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\temp
Using JRE_HOME:        C:\Users\murugesandins\cygwin\home\murugesandins\jira\jdk-11.0.9
Using CLASSPATH:       C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\bin\bootstrap.jar;C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\bin\tomcat-juli.jar
Using CATALINA_OPTS:
eval "/cygdrive/c/PROGRA~2/Jdk17/bin/java.exe" "-Djava.util.logging.config.file=C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19/conf/logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager  -Djdk.tls.ephemeralDHKeySize=2048 -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED  -classpath "C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\bin\bootstrap.jar;C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\bin\tomcat-juli.jar" -Dcatalina.base="C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19" -Dcatalina.home="C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19" -Djava.io.tmpdir="C:\Users\murugesandins\cygwin\home\murugesandins\apache-tomcat-11.0.0-M19\temp" org.apache.catalina.startup.Bootstrap start
Tomcat started.
$ ps -eaf | grep java
murugesa    2449       1 pty0     20:02:13 /cygdrive/c/Program Files (x86)/Jdk17/bin/java
$ tasklist | grep java
java.exe                      9064 Services                   0    105,352 K
http://127.0.0.1:7777/
at browser is working fine.
Hence you need to set related port number at server.xml file at your OS

Looks like i dont need to redirect I just wanted to use the other url to be working in the same way

https://example.com --> this not
https://www.servercom:7777 -->this works

So I see you used http.conf and all, I dont really understand if you need this ? I just used localhost in server.xml file

</Host>
<Host name="localhost" appBase="towl"
unpackWARs="true" autoDeploy="true">

How can i make https://example.com this url working ?

Last edited by sag2662; 04-23-2024 at 02:16 AM.
 
Old 04-22-2024, 11:04 PM   #6
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
I have modified conf/server.xml
Code:
    <Connector port="7777" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
Code:
$ bin/shutdown.sh
$ bin/startup.sh
After this
http://127.0.0.1
http://127.0.0.1:7777
working fine at locahost.
Code:
$ bin/shutdown.sh
Using CATALINA_BASE:   C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19
Using CATALINA_HOME:   C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19
Using CATALINA_TMPDIR: C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\temp
Using JRE_HOME:        C:\Users\murugesan_openssl\home\murugesan_openssl\jira\jdk-11.0.9
Using CLASSPATH:       C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\bin\bootstrap.jar;C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\bin\tomcat-juli.jar
Using CATALINA_OPTS:
eval "/cygdrive/c/PROGRA~2/Jdk17/bin/java.exe" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager  -Djdk.tls.ephemeralDHKeySize=2048 -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -classpath "C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\bin\bootstrap.jar;C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\bin\tomcat-juli.jar" -Dcatalina.base="C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19" -Dcatalina.home="C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19" -Djava.io.tmpdir="C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\temp" org.apache.catalina.startup.Bootstrap stop
$ bin/startup.sh
exec bin/catalina.sh start
Using CATALINA_BASE:   C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19
Using CATALINA_HOME:   C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19
Using CATALINA_TMPDIR: C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\temp
Using JRE_HOME:        C:\Users\murugesan_openssl\home\murugesan_openssl\jira\jdk-11.0.9
Using CLASSPATH:       C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\bin\bootstrap.jar;C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\bin\tomcat-juli.jar
Using CATALINA_OPTS:
eval "/cygdrive/c/PROGRA~2/Jdk17/bin/java.exe" "-Djava.util.logging.config.file=C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19/conf/logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager  -Djdk.tls.ephemeralDHKeySize=2048 -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED  -classpath "C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\bin\bootstrap.jar;C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\bin\tomcat-juli.jar" -Dcatalina.base="C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19" -Dcatalina.home="C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19" -Djava.io.tmpdir="C:\Users\murugesan_openssl\home\murugesan_openssl\apache-tomcat-11.0.0-M19\temp" org.apache.catalina.startup.Bootstrap start
Tomcat started.
$ /cygdrive/c/WINDOWS/system32/NETSTAT.EXE -nato | grep ":80|:7777"
  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       2688     InHost
  TCP    0.0.0.0:7777           0.0.0.0:0              LISTENING       2688     InHost
  TCP    [::]:80                [::]:0                 LISTENING       2688     InHost
  TCP    [::]:7777              [::]:0                 LISTENING       2688     InHost

Last edited by murugesandins; 04-23-2024 at 06:48 PM. Reason: Added [code]code[/code] Removed quote
 
Old 04-23-2024, 01:46 AM   #7
sag2662
Member
 
Registered: Sep 2022
Posts: 67

Original Poster
Rep: Reputation: 0
Can you please put server.xml fileconfigurazion for host and connectors. I am using https not http. Thanks for your time
 
Old 04-23-2024, 02:14 AM   #8
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
1)
can you edit your comment and remove:
Thank you for removing invalid comments.
2)
Sample server.xml file I have tried(after download sample file from internet) at localhost
you can compare attached file with your file and view related requirements at your environment.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="9090" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!-- OpenSSL support using Tomcat Native -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" />
  <!-- OpenSSL support using FFM API from Java 22 -->
  <!-- <Listener className="org.apache.catalina.core.OpenSSLLifecycleListener" /> -->
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         HTTP Connector: /docs/config/http.html
         AJP  Connector: /docs/config/ajp.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 7777
    -->
<servlet-mapping>
  <servlet-name>default</servlet-name>
  <url-pattern>/css/*</url-pattern>
</servlet-mapping>
    <Connector port="7777" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="1234" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               redirectPort="8443" />
    -->

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>
Do you want me to use https instead of http at my localhost ?
That will take time.
if required, send me your server.xml and I will try the same at localhost (if required)

Last edited by murugesandins; 04-23-2024 at 05:15 AM.
 
Old 04-23-2024, 03:09 AM   #9
sag2662
Member
 
Registered: Sep 2022
Posts: 67

Original Poster
Rep: Reputation: 0
Thank you very much for your fast response. Removed the quote you have asked for.


Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!-- APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">

    <Connector port="8080" protocol="HTTP/1.1"
               address="127.0.0.1"
               connectionTimeout="20000"
               maxParameterCount="1000" />

    <Connector port="7777" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true"
               scheme="https" secure="true" clientAuth="false"
               sslProtocol="TLS" maxHttpHeaderSize="8192"
               keystoreFile="/opt/home/myhome/keystoreFile"

    <Engine name="Catalina" defaultHost="localhost">

      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
          <Context path="" docBase="grok" />
      </Host>
      <Host name="example.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
         <Context path="" docBase="grok" />
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

To be clear: localhost: www.server.com
alias name Or dns of localhost: example.com

https://www.server.com:7777/example --> works
https://example.com:7777 --> works
https://example.com--> doesnotwork

I am suspecting some SSL authentication is not properly set here. as https://example.com redirects toport 443 by default ?

Last edited by sag2662; 04-23-2024 at 03:49 AM.
 
Old 04-23-2024, 05:28 AM   #10
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
01)
Remove all words having the letters orry at your comment.

02)
ttps://www.server.com:7777/example --> works
https://example.com:7777 --> works
https://example.com--> doesnotwork
I need to know your comment:
Actually tomcat was configured https to use 7777
Hence you need 80 port as well at https Since default port without port number is 80)?
a) check 80 is not in use
I have stopped windows IIS before providing my first comment
validate using netstat
b) validate using
lsof Example at my cygwin:
Code:
$ lsof -i:22
sshd.exe        7048           Services 0 9380  K PORT: 22
sshd.exe        7048           Services 0 9380  K PORT: 22
$ type lsof
lsof is hashed (/home/murugesan_openssl/lsof)
$#mylsof using /cygdrive/c/Windows/System32/netstat.exe and tasklist.exe at windows. Use /sbin/lsof or /usr/sbin/lsof or related path.
$# validate the port numbers using lsof for following port numbers:
$# 7777 80
FEW MORE UPDATES:
$ lsof -i:80
java.exe 5716 Services 0 113932 K PORT: 7777 80 9090
java.exe 5716 Services 0 113932 K PORT: 7777 80 9090
I am having following lines at server.xml
Code:
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
Hence 80 being used by default http port which needs to be the default port.

My server.xml having opening and close tag for:
<Connector .../>
How about your .xml file ?
[/code]
I cannot copy your .xml file to my localhost:
Reason:
I need to re-create all pem/crt/jsk files a lot...

Last edited by murugesandins; 04-23-2024 at 05:45 AM.
 
Old 04-23-2024, 06:26 AM   #11
sag2662
Member
 
Registered: Sep 2022
Posts: 67

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by murugesandins View Post
01)
Remove all words having the letters orry at your comment.

02)
ttps://www.server.com:7777/example --> works
https://example.com:7777 --> works
https://example.com--> doesnotwork
I need to know your comment:

Actually tomcat was configured https to use 7777
Hence you need 80 port as well at https Since default port without port number is 80)?
a) check 80 is not in use
I have stopped windows IIS before providing my first comment
validate using netstat
b) validate using
lsof Example at my cygwin:
Code:
$ lsof -i:22
sshd.exe        7048           Services 0 9380  K PORT: 22
sshd.exe        7048           Services 0 9380  K PORT: 22
$ type lsof
lsof is hashed (/home/murugesan_openssl/lsof)
$#mylsof using /cygdrive/c/Windows/System32/netstat.exe and tasklist.exe at windows. Use /sbin/lsof or /usr/sbin/lsof or related path.
$# validate the port numbers using lsof for following port numbers:
$# 7777 80
FEW MORE UPDATES:
$ lsof -i:80
java.exe 5716 Services 0 113932 K PORT: 7777 80 9090
java.exe 5716 Services 0 113932 K PORT: 7777 80 9090
I am having following lines at server.xml
Code:
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
Hence 80 being used by default http port which needs to be the default port.

My server.xml having opening and close tag for:
<Connector .../>
How about your .xml file ?
[/code]
I cannot copy your .xml file to my localhost:
Reason:
I need to re-create all pem/crt/jsk files a lot...
1) I hope, I removed all the comments.
Here we are using 8080 instead of 80 and I modfied 8443 for https
Code:
lsof -i:8443
COMMAND   PID     USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
java    53430 towl   tmp  IPv6 2904825571      0t0  TCP *:https (LISTEN)
lsof -i:8080
COMMAND   PID     USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
java    53430 towl   tmp  IPv6 2904825570      0t0  TCP *:cache (LISTEN)
Even I have opening and close tag for, please see the xml file
<Connector .../>


https://www.server.com:8443/example --> works
https://example.com:8443 --> works
https://example.com--> doesnotwork --> How can i make with out port to be working ?

Last edited by sag2662; 04-23-2024 at 06:45 AM.
 
Old 04-23-2024, 08:50 AM   #12
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
As of now I cannot help you since I am unable to reproduce the same at localhost.
01)
I tried copying your server.xml(after a backup of my server.xml)
unable to start tomcat here using your xml file (dependent on openssl/keytool)
02)
Here goes the way I am performing apache tomcat at windows:
a) download apache-tomcat-11.0.0-M19.zip
b) unzip and use the server.xml file I gave you without using any openssl.exe or and /cygdrive/c/PROGRA~2/Jdk17/bin/keytool at my system.
Hence I am able to access:
http://127.0.0.1:7777/mis_interest_valid_Dates.html
http://127.0.0.1:7777/ and all sub pages.
I made changes to perform:
.css file and .js file acesss using tomcat config files.
However I need to search or perform related(all) actions to change http to https here.
if you have related automated commands/$HISTFILE for openssl share the same here for me to reproduce at my system => Using that I can resolve your error.

How about:
Code:
lsof -i:80
lsof -i:443
netstat -nato | grep -E "80|443"

Last edited by murugesandins; 04-23-2024 at 06:49 PM. Reason: Removed quote
 
Old 04-23-2024, 09:13 AM   #13
sag2662
Member
 
Registered: Sep 2022
Posts: 67

Original Poster
Rep: Reputation: 0
Hi Thanks again, I have never worked with tomcat before and I am stuck where the issue lies.
search sorry in this page.[/QUOTE]

Quote:
I removed all, I think you have to do the same
Code:
lsof -i:80 --> nothing comesup
lsof -i:443 --> nothing comesup
netstat -nato | grep -E "80|443"
tcp6       0      0 :::8080                 :::*                    LISTEN      off (0.00/0/0)
tcp6       0      0 :::8443                 :::*                    LISTEN      off (0.00/0/0)
 
Old 04-23-2024, 07:25 PM   #14
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
Before making changes to server.xml make a backup.
My backup names:
Example at my system:
Code:
$ /usr/bin/ls -ltr server.xml*
-rwxrwxr-x+ 1 murugesan_openssl openssl 7263 Apr 23 10:41 server.xml.working.IDA23241041AMIST
-rw-rw-r--+ 1 murugesan_openssl openssl 2964 Apr 23 15:41 server.xml.lq.23Apr0341PMIST
-rwxrwxr-x+ 1 murugesan_openssl openssl 7418 Apr 23 15:41 server.xml.localhost.IDA23240341PMIST
-rwxrwxr-x+ 1 murugesan_openssl openssl 7001 Apr 23 19:22 server.xml.OriginalFromZipFile.23240722AMIST
-rwxrwxr-x+ 1 murugesan_openssl openssl 7351 Apr 23 19:23 server.xml.working.IDA23240723AMIST
-rwxrwxr-x+ 1 murugesan_openssl openssl 7966 Apr 24 05:41 server.xml
-rwxrwxr-x+ 1 murugesan_openssl openssl 7966 Apr 24 05:48 server.xml.working.IDA23240541AMIST
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Server port="9090" shutdown="SHUTDOWN">
        <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <Listener className="org.apache.catalina.core.AprLifecycleListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
  <Service name="Catalina">
<servlet-mapping>
  <servlet-name>default</servlet-name>
  <url-pattern>/css/*</url-pattern>
</servlet-mapping>
    <Connector port="7777" protocol="HTTP/1.1"
                connectionTimeout="20000"
                redirectPort="443" />
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443" />
    <Connector
                connectionTimeout="20000"
                acceptCount="100"
                scheme="https"
                secure="true"
                clientAuth="false"
                sslProtocol="TLS"
                port="443"
                maxThreads="150"
                protocol="org.apache.coyote.http11.Http11NioProtocol"
                keystoreFile="PATH_TO_KEY_STORE"
                keystorePass="KEY_STORE_PASS"
                keyAlias="KEY_STORE_ALIAS"
                SSLEnabled="true">
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
                <Certificate certificateKeyFile="C:/Users/murugesan_openssl/cygwin/home/murugesan_openssl/apache-tomcat-11.0.0-M19/conf/privkey.pem"
                        certificateFile="C:/Users/murugesan_openssl/cygwin/home/murugesan_openssl/apache-tomcat-11.0.0-M19/conf/cert.pem"
                        certificateChainFile="C:/Users/murugesan_openssl/cygwin/home/murugesan_openssl/apache-tomcat-11.0.0-M19/conf/chain.pem"
                type="RSA" />
        </SSLHostConfig>
    </Connector>
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>
    </Engine>
  </Service>
</Server>
Code I have used for openssl cert files
Code:
#!/bin/bash
if [[ ! -f localhost-rsa.jks ]]
then
        echo Openssl@123
        /cygdrive/c/PROGRA~2/Jdk17/bin/keytool -genkey -noprompt -alias tomcat-localhost -keyalg RSA -keystore localhost-rsa.jks -keypass Openssl@123 -storepass Openssl@123 -dname "CN=tomcat-cert, OU=GIS, O=GIS, L=Bangalore, ST=Karnataka, C=IN"
fi
/usr/bin/file localhost-rsa.jks
if [[ ! -f privkey.pem.rsa.key ]]
then
        echo Openssl@123
        echo Openssl@123
        /usr/bin/openssl rsa -in privkey.pem -out privkey.pem.rsa.key
fi
/usr/bin/file privkey.pem.rsa.key
if [[ ! -f privkey.pkcs1.pem ]]
then
        echo Openssl@123
        /usr/bin/openssl rsa -in privkey.pem -out privkey.pkcs1.pem
fi
/usr/bin/file privkey.pkcs1.pem
if [[ ! -f cert.pem ]]
then
        echo IN
        echo Bangalore
        echo Karnataka
        echo GIS
        echo GIS
        echo 127.0.0.1
        echo myEmail@mydomainDotcom
        /usr/bin/openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout privkey.pem -out cert.pem
fi
/usr/bin/file cert.pem
if [[ ! -f cert.pem ]]
then
        echo Openssl@123
        /usr/bin/openssl crl2pkcs7 -nocrl -certfile cert.pem
fi
/usr/bin/file cert.pem
After these changes my acess test results:
http://127.0.0.1=> automatically redirecting to https://127.0.0.1
http://127.0.0.1/mis_interest_valid_Dates.html => automatically redirecting to https://127.0.0.1/mis_interest_valid_Dates.html
Hence make similar changes at your server.xml(backup files and restart)

Can you share your timing ?
My timing:
Code:
$ /usr/bin/date "+%a %d-%b-%Y %I:%M %p %Z"
Wed 24-Apr-2024 05:59 AM IST
$# Dharmapuri Tamilnadu India and
$# Bangalore Karnataka India
If I open following url:
https://127.0.0.1:443/mis_interest_valid_Dates.html
it is automatically redirecting to:
https://127.0.0.1/mis_interest_valid_Dates.html

Last edited by murugesandins; 04-23-2024 at 07:33 PM. Reason: $# automation test result Pass.
 
Old 04-24-2024, 02:38 AM   #15
sag2662
Member
 
Registered: Sep 2022
Posts: 67

Original Poster
Rep: Reputation: 0
Thank you very much for your time, I tried to change the configuration like you provided server.xml file and now I cannot reach any of the urls. From my point of view, 8443 and 443 are two different ports. As the certificate is already there for 8443 and its working fine. I would assume that we need new certificate for 443 and then configure in apache tomcat. Not sure if this is solution. Also my server is not listening on port 443, because of this also its not possible to redirect port from 443 to 8443
My time zone is CEST.
when i do wget, I have this

Code:
Proxy tunneling failed: Gateway TimeoutUnable to establish SSL connection

Last edited by sag2662; 04-24-2024 at 03:08 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to set up Apache webserver proxy in front of Apache Tomcat on Red Hat Linux LXer Syndicated Linux News 0 10-01-2018 01:32 PM
apache webserver and tomcat fachhoch@gmail.com Linux - Newbie 1 05-11-2012 09:40 PM
Session replication using apache+mod_jk+tomcat(5.5.28-veriosn of tomcat) sreejithp Linux - Server 1 12-24-2010 06:46 AM
apache-tomcat and jakarta-tomcat shifter Programming 1 07-28-2007 10:36 PM
Why use Apache with Tomcat rather than just Tomcat itself? davee Linux - Software 1 08-21-2003 09:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration