Access the javaweb project deployed on the server through the domain name

Because I don’t know anything about domain name access, I am at a loss as to where to start when I encounter problems, and I don’t even know where I am going wrong. , so record it.
1. Port mapping
server device. If you apply for a domain name, the port will point to port 80 by default. Here the service is published in tomcat and uses port 8080. Therefore, port mapping is required to map port 80 to port 8080.
Example: http://127.0.0.1 is actually equivalent to: http://127.0.0.1:80 uses port 80, because only port 80 can be omitted
Another example: http://www.sohu.com/ Actually, etc. Price at: www.sohu.com:80

The following is the port mapping method in Windows system (iptables can be used in Linux system)
port mapping can use nginx (need to install nginx on the server) or netsh.

The netsh used here, netsh is built-in with win7 and above, and supports IPv4 and IPv6. Direct cmd, configure on the command line

// Add port mapping 
netsh interface portproxy add v4tov4 listenaddress=121.21.36.190 listenport=81 connectaddress=192.168.99.10 connectport=81
 // Map port 81 with server IP address 121.21.36.190 to port 192.168.99.10 with server IP address 8080. Now accessing 121.21.36.190:81 is actually the same as accessing 192.168.99.10:8080

// View the list of configured port mappings 
netsh interface portproxy show v4tov4

// Delete port mapping 
netsh interface portproxy delete v4tov4 listenaddress=121.21.36.190 listenport=81

A problem encountered here is that the ip address used for port mapping is the server's internal network ip, not the server's public network ip. Configuration as shown

Later, I found that it seems that you can do it without port mapping. Just change the port of Tomcat to 80.

<Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
            redirectPort="8443" />

Just change port="8080" to port="80".

Second, configure Tomcat

Open the tomcat/conf/server.conf file
1. Modify the domain name. There are two places to be changed here, as shown in the figure


2. Configure docBase. Add <Context> inside <Host></Host>. path="" docBase=The absolute path of the project on the server, as shown in the figure

The configured server.conf is as follows:

    
    <Engine name="Catalina" defaultHost="***.top">

      <!--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="***.top"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
      
      <Context docBase="C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\SpringDemo" path="" reloadable="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 "%r" %s %b" />

      </Host>
    </Engine>

 

Reference: Port mapping Tomcat configuration domain name 
under windows 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326032380&siteId=291194637
Recommended