{"id":7011,"date":"2017-09-12T15:38:19","date_gmt":"2017-09-12T07:38:19","guid":{"rendered":"http:\/\/rmohan.com\/?p=7011"},"modified":"2017-09-12T15:38:19","modified_gmt":"2017-09-12T07:38:19","slug":"nginx-tomcat-installation-configuration","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7011","title":{"rendered":"Nginx  Tomcat installation configuration"},"content":{"rendered":"<p>Tomcat is a lightweight application server, in the small and medium-sized system and concurrent access to the user is not a lot of occasions are widely used, is the development and debugging JSP program of choice. It can be argued that when a Tomcat server is configured on a machine, it can use it to respond to requests for HTML pages. In fact Tomcat is part of the Nginx server extension, but it is run independently, so when you run tomcat, it actually runs as a separate process with Nginx.<\/p>\n<p>Install tomcat<\/p>\n<p>Tomcat installation is divided into two steps: install the JDK and install Tomcat.<\/p>\n<p>The JDK (Java Development Kit) is a product of Sun Microsystems for Java developers. Since the introduction of Java, JDK has become the most widely used Java SDK. JDK is the core of the entire Java, including the Java runtime environment, Java tools and Java-based class library. So in order to run the jsp program must have JDK support, of course, the premise is to install Tomcat JDK installed.<\/p>\n<p>Install the JDK<\/p>\n<p>Download JDK<\/p>\n<p>cd \/usr\/local\/src\/<\/p>\n<p>Download JDK official website:<\/p>\n<p>http:\/\/www.Oracle.com\/technetwork\/java\/javase\/downloads\/jdk8-downloads-2133151.html<\/p>\n<p>rpm -ivh jdk-7-linux-i586.rpm<\/p>\n<p>vim \/etc\/profile<\/p>\n<p>JAVA_HOME=\/usr\/java\/jdk1.7.0_45<\/p>\n<p>JRE_HOME=\/usr\/java\/jdk1.7.0_45\/jre<\/p>\n<p>PATH=$PATH:$JAVA_HOME\/bin:$JRE_HOME\/bin<\/p>\n<p>CLASSPATH=:$JAVA_HOME\/lib\/dt.jar:$JAVA_HOME\/lib\/tools.jar:$JRE_HOME\/lib<\/p>\n<p>export JAVA_HOME JRE_HOME PATH CLASSPATH<\/p>\n<p>[root@localhost ~]# source \/etc\/profile  <\/p>\n<p>[root@localhost ~]# echo $PATH  <\/p>\n<p>java -version<\/p>\n<p>Install Tomcat<\/p>\n<p>cd \/usr\/local\/src\/<\/p>\n<p>wget http:\/\/www.aminglinux.com\/bbs\/data\/attachment\/forum\/apache-tomcat-7.0.14.tar.gz<\/p>\n<p>If you think this version is not suitable, you can go to the official website (http:\/\/tomcat.apache.org\/) download.<\/p>\n<p>tar zxvf apache-tomcat-7.0.14.tar.gz<\/p>\n<p>mv apache-tomcat-7.0.14 \/usr\/local\/tomcat<\/p>\n<p>cp -p \/usr\/local\/tomcat\/bin\/catalina.sh \/etc\/init.d\/tomcat<\/p>\n<p>vim \/etc\/init.d\/tomcat<\/p>\n<p>Add the following in the second line:<\/p>\n<p># chkconfig: 112 63 37<\/p>\n<p># description: tomcat server init script<\/p>\n<p># Source Function Library<\/p>\n<p>. \/etc\/init.d\/functions<\/p>\n<p>JAVA_HOME=\/usr\/java\/jdk1.7.0_45<\/p>\n<p>CATALINA_HOME=\/usr\/local\/tomcat<\/p>\n<p>After saving the file, do the following:<\/p>\n<p>chmod 755 \/etc\/init.d\/tomcat<\/p>\n<p>chkconfig &#8211;add tomcat<\/p>\n<p>chkconfig tomcat on<\/p>\n<p>Start tomcat:<\/p>\n<p>service tomcat start<\/p>\n<p>To see if the boot is successful:<\/p>\n<p>ps aux | grep tomcat<\/p>\n<p>If there is a process, please enter http: \/\/ IP: 8080 in the browser \/ you will see the main interface tomcat.<\/p>\n<p>tomcat<\/p>\n<p>1. Configure the access port for the tomcat service<\/p>\n<p>tomcat default is activated 8080, if you want to modify to 80, you need to modify the server.xml file:<\/p>\n<p>vim \/usr\/local\/tomcat\/conf\/server.xml<\/p>\n<p>turn up:<\/p>\n<p><Connector port=\"8080\" protocol=\"HTTP\/1.1\"\n\n\n\n<Connector port=\"80\" protocol=\"HTTP\/1.1\"\n\n2. \n\ncd \/usr\/local\/tomcat\/conf\/\n\nvim server.xml\n\n<\/Host><\/p>\n<p><Host name=\"www.rmohan.com\" appBase=\"\/data\/tomcatweb\"\n\n    unpackWARs=\"false\" autoDeploy=\"true\"\n\n    xmlValidation=\"false\" xmlNamespaceAware=\"false\"><\/p>\n<p>    <Context path=\"\" docBase=\".\/\" debug=\"0\" reloadable=\"true\" crossContext=\"true\"\/><\/p>\n<p><\/Host><\/p>\n<p>tomcat:<\/p>\n<p>service tomcat stop<\/p>\n<p>service tomcat start<\/p>\n<p>tomcat<\/p>\n<p>tomcat<\/p>\n<p>vim \/data\/tomcatweb\/app.jsp<\/p>\n<p><html><body><center><\/p>\n<p>    Now time is: <%=new java.util.Date()%><\/p>\n<p><\/center><\/body><\/html><\/p>\n<p>[root@localhost ~]# curl -xlocalhost:80 www.rmohan.com\/app.jsp<\/p>\n<p><html><body><center><\/p>\n<p>    Now time is: Thu Jun 13 15:26:03 CST 2013<\/p>\n<p><\/center><\/body><\/html><\/p>\n<p>tomcat connection mysql database:<\/p>\n<p>cat jdbc.properties<\/p>\n<p>jdbc.driverClassName=com.mysql.jdbc.Driver<\/p>\n<p>jdbc.url=jdbc:mysql:\/\/localhost:3306\/rmohan?useUnicode=true&amp;characterEncoding=utf-8<\/p>\n<p>jdbc.username=WordPress<\/p>\n<p>jdbc.password=WordPress<\/p>\n<p>hibernate.dialect=org.hibernate.dialect.MySQLDialect<\/p>\n<p>hibernate.show_sql=false<\/p>\n<p>hibernate.format_sql=true<\/p>\n<p>hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider<\/p>\n<p>hibernate.cache.use_query_cache=true<\/p>\n<p>hibernate.schemaUpdate=false<\/p>\n<p>Nginx configuration all jsp pages are handled by tomcat:<\/p>\n<p>server {<\/p>\n<p>   listen 80;<\/p>\n<p>   server_name rmohan.com www.rmohan.com;<\/p>\n<p>   index index.html index.jsp;<\/p>\n<p>   root \/home\/www\/rmohan\/rmohan;<\/p>\n<p>   rewrite ^\/(.*)$ https:\/\/www.rmohan.com\/$1 permanent;<\/p>\n<p>   location ~ \/\\. { access_log off; log_not_found off; deny all; }<\/p>\n<p>   location ~* (\\.jsp)|(\\.do)$ {<\/p>\n<p>       include proxy.conf;<\/p>\n<p>       proxy_pass http:\/\/127.0.0.1:8080;<\/p>\n<p>   }<\/p>\n<p>   location \/rmohan {<\/p>\n<p>        root \/home\/www\/rmohan;<\/p>\n<p>        include proxy.conf;<\/p>\n<p>       proxy_pass http:\/\/127.0.0.1:8080;<\/p>\n<p>   }<\/p>\n<p>}<\/p>\n<p>server {<\/p>\n<p>   listen 443 ssl;<\/p>\n<p>   server_name rmohan.com www.rmohan.com;<\/p>\n<p>   index index.html index.jsp;<\/p>\n<p>   root \/home\/www\/rmohan\/rmohan;<\/p>\n<p>ssl on;<\/p>\n<p>ssl_protocols TLSv1 TLSv1.1 TLSv1.2;<\/p>\n<p>#ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;<\/p>\n<p>#ssl_prefer_server_ciphers on;<\/p>\n<p>#ssl_dhparam \/etc\/pki\/tls\/private\/dhparam.pem;<\/p>\n<p>ssl_certificate \/etc\/pki\/tls\/certs\/rmohan.com.crt;<\/p>\n<p>ssl_certificate_key \/etc\/pki\/tls\/private\/rmohan.com.key;<\/p>\n<p>#ssl_session_tickets off;<\/p>\n<p>#ssl_session_timeout 1d;<\/p>\n<p>#ssl_session_cache shared:SSL:1m;<\/p>\n<p>add_header Strict-Transport-Security &#8216;max-age=31536000&#8217;; # remember the certificate for a year and automatically connect to HTTPS for this domain<\/p>\n<p>   location ~ \/\\. { access_log off; log_not_found off; deny all; }<\/p>\n<p>   location ~* (\\.jsp)|(\\.do)$ {<\/p>\n<p>       include proxy.conf;<\/p>\n<p>       proxy_pass http:\/\/127.0.0.1:8080;<\/p>\n<p>   }<\/p>\n<p>   location \/rmohan {<\/p>\n<p>        root \/home\/www\/rmohan;<\/p>\n<p>        include proxy.conf;<\/p>\n<p>       proxy_pass http:\/\/127.0.0.1:8080;<\/p>\n<p>   }<\/p>\n<p>}<\/p>\n<p>Tomcat<\/p>\n<p>vi \/usr\/local\/tomcat\/conf\/server.xml +71<\/p>\n<p><Connector port=\"8080\" protocol=\"org.apache.coyote.http11.Http11AprProtocol\"\n\n                 enableLookups=\"false\" acceptCount=\"1000\"\n\n                 useBodyEncodingForURI=\"true\"\n\n                 URIEncoding=\"UTF-8\"\n\n                 connectionTimeout=\"20000\"\n\n                 redirectPort=\"8443\" \/><\/p>\n<p>     <!-- A \"Connector\" using the shared thread pool--><\/p>\n<p>     <!--\n\n     <Connector executor=\"tomcatThreadPool\"\n\n                port=\"8080\" protocol=\"HTTP\/1.1\"\n\n                connectionTimeout=\"20000\"\n\n                redirectPort=\"8443\" \/>\n\nvi \/usr\/local\/tomcat\/conf\/server.xml +128\n\n       <Host name=\"localhost\"  appBase=\"\/home\/www\/rmohan\"\n\n             unpackWARs=\"true\" autoDeploy=\"true\">\n\n        <Context reloadable=\"true\" docBase=\"rmohan\" path=\"\" \/>\n\nTomcat?\n\ncp -r \/usr\/local\/tomcat  \/usr\/local\/tomcat2\n\nAnd then modify the corresponding port and virtual host can be.\n\nAfter saving, restart tomcat:\n\nservice tomcat stop\n\nservice tomcat start\n\nCheck Tomcat startup process:\n\nps -ef | grep tomcat\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tomcat is a lightweight application server, in the small and medium-sized system and concurrent access to the user is not a lot of occasions are widely used, is the development and debugging JSP program of choice. It can be argued that when a Tomcat server is configured on a machine, it can use it to [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7011"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7011"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7011\/revisions"}],"predecessor-version":[{"id":7012,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7011\/revisions\/7012"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}