วันศุกร์ที่ 10 พฤษภาคม พ.ศ. 2562

Install Apache Tomcat 8.5 on Ubuntu Server 18.04

# Search Package Apache Tomcat 8
sudo apt update
sudo apt search tomcat8*

# List
tomcat8/bionic-updates,bionic-security 8.5.39-1ubuntu1~18.04.1 all
  Apache Tomcat 8 - Servlet and JSP engine

tomcat8-admin/bionic-updates,bionic-security 8.5.39-1ubuntu1~18.04.1 all
  Apache Tomcat 8 - Servlet and JSP engine -- admin web applications

tomcat8-common/bionic-updates,bionic-security 8.5.39-1ubuntu1~18.04.1 all
  Apache Tomcat 8 - Servlet and JSP engine -- common files

tomcat8-docs/bionic-updates,bionic-security 8.5.39-1ubuntu1~18.04.1 all
  Apache Tomcat 8 - Servlet and JSP engine -- documentation

tomcat8-examples/bionic-updates,bionic-security 8.5.39-1ubuntu1~18.04.1 all
  Apache Tomcat 8 - Servlet and JSP engine -- example web applications

tomcat8-user/bionic-updates,bionic-security 8.5.39-1ubuntu1~18.04.1 all
  Apache Tomcat 8 - Servlet and JSP engine -- tools to create user instances

# Install Apache Tomcat 8, It will install [jre] and [tomcat8-common] with.
sudo apt install tomcat8

# Check Apache Tomcat 8 Status
sudo systemctl status tomcat8

# File Location
/var/lib/tomcat8/
/etc/tomcat8/

Check http://your-domain:8080 at your web browser




Install tomcat8-admin Package

sudo apt install tomcat8-admin

Create user admin at file "/etc/tomcat/tomcat-users.xml" by add rolename, username and password
- Application Manager use http://your-domain:8080/manager
- Host Manager use http://your-domain:8080/host-manager
<?xml version="1.0" encoding="UTF-8"?>
  <tomcat-users xmlnx="...>

    <role rolename="admin-gui"/>
    <role rolename="manager-gui"/>
    <user username="admin" password="admin" role="admin-gui,manager-gui"/>

  </tomcat-users>

Application Manager


Host Manager





Change Web Server Port 8080 To 80

We have 2 choice to change port

1. Config at server.xml

Web Server config store in /etc/tomcat/server.xml
To change web port we have to config this file
# About line 70 at Connector tag port 8080
<Connector port="8080" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" />

# Change 8080 to 80
<Connector port="80" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" />

# Save and Restart Apache Tomcat 8

2. Use iptables to forward 8080 to 80

Reference: Linux port redirection with iptables
# 80 is source port to 8080 is destination port
# eth0 is name of network interface
sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -j REDIRECT --to-port 8080

# list iptables rule and 
sudo iptables -t nat -L PREROUTING

# remove iptables rule / 1 is line number
sudo iptables -t nat -D PREROUTING 1 




Add Certification for HTTPS Protocal

Reference: Convert pfx to jks | Install SSL Tomcat 8.0 | Install SSL Tomcat 7.0

For Tomcat 8.5 Following This Step

1.Convert .pfx to .jks

keytool -importkeystore -srckeystore source.pfx -srcstoretype PKCS12
 -destkeystore destination.jks -deststoretype JKS

2. Config server.xml file

# About line 90 at Connector tag port 8443 uncomment and edit 2 value
# certificateKeystoreFile and add certificateKeystorePassword if keystore have password

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
   maxThreads="150" SSLEnabled="true">
   <SSLHostConfig>
      <Certificate certificateKeystoreFile="conf/certificate.cert.jks"
                   certificateKeystorePassword="12345678"
                   type="RSA" />
      </SSLHostConfig>
</Connector>

# Save file and restart apache tomcat

Example Config in Tomcat 7.0

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
           sslProtocol="TLS" scheme="https" secure="true"
           clientAuth="false" maxThreads="150" 
           keystoreFile="conf/certificate.pfx"
           keystoreType="PKCS12"
           keystorePass="12345678" />




Reference: Deploy as Root

ไม่มีความคิดเห็น:

แสดงความคิดเห็น