Nginx+Tomcat realize 80 port forwarding 8080 port

Posted by pb4life55 on Wed, 08 Jan 2020 18:37:55 +0100

Nginx+Tomcat implements port 80 forwarding port 8080. First Install Nginx Secondly, install jdk, that is, configure java environment, then install Tomcat, and then modify forwarding, proxy address and port.

Install and configure Nginx

Install JAVA

  • I use jdk7 and tomcat7 here
[root@nginx ~]# ls jdk-7u79-linux-x64.tar.gz 
jdk-7u79-linux-x64.tar.gz
  • Extract the specified path
[root@nginx ~]# tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/
  • Create soft links for easy updates
[root@nginx ~]# ln -s /usr/local/jdk1.7.0_79/  /usr/local/java
  • Add environment variable
[root@nginx ~]# cat  /etc/profile    ##Finally add the following
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin

##Effective
[root@nginx ~]# source /etc/profile
  • Test, a hello world code
[root@nginx ~]# cat test.java 
public class test {
    public static void main (String[] args)
    {
        System.out.println("hello world! JAVA!");
    }
}
  • Compile, run
[root@nginx ~]# javac test.java 
[root@nginx ~]# java test
hello world! JAVA!
[root@nginx ~]#

Install Tomcat

  • I use jdk7 and tomcat7 here
[root@nginx ~]# ls apache-tomcat-7.0.37.tar.gz 
apache-tomcat-7.0.37.tar.gz
  • Extract to the specified path
[root@nginx ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
  • Create soft links for easy updates
[root@nginx ~]# ln -s /usr/local/apache-tomcat-7.0.37/ /usr/local/tomcat
  • open
[root@nginx tomcat]# sh /usr/local/tomcat/bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
  • Visit http:ip:8080

    So far, Tomcat has been successfully configured. Now, modify the Nginx configuration file

Configure Nginx

  • Listen: listen to port 80
  • Server name: forward to the specified address: Port
  • Proxy pass: proxy to the specified address: Port
[root@nginx ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf


-Load Nginx smoothly

[root@nginx ~]# nginx -s reload
  • Web access http:ip default port 80 has jumped to 8080

Topics: Nginx Tomcat Java JDK