王 静凯,

On 1/4/22 00:46, 王 静凯 wrote:
Hi,
        I use httpServletRequest.getServerPort() to get the port in my jsp.
When the tomcat listen 8080 and nginx listen 80.
Nginx has set ‘proxy_set_header Host $http_host’.

What is the value of $http_host?

Then the port  80 mapping to Internet via 10001.
Use httpServletRequest.getHeader(“Host”) I can get the correct value of Host 
header – “InternetIP:10001”.
But  httpServletRequest.getServerPort() did not return 10001 and return 80.
How could I solve it?
Btw, to set proxyPort in connector can not take effect. But proxyName work.

Have you read about the RemoteIPValve?

Using tomcat 8.5.72 and jre 1.8.0_201 on CentOS7.2009
        My server.xml:

        ````
        <?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
   <Listener className="org.apache.catalina.core.AprLifecycleListener" 
SSLEngine="on" />
   <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"
                connectionTimeout="20000"
                redirectPort="8443" maxHttpHeaderSize="8192" maxThreads="4000" minSpareThreads="1000" 
maxSpareThreads="2000" enableLookups="false" acceptCount="2000" URIEncoding="UTF-8" maxPostSize="4194304" />
     <Engine name="Catalina" defaultHost="localhost" startStopThreads="0">
       <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" startStopThreads="0">
         <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>
````

getServerPort

int getServerPort()
Returns the port number to which the request was sent. It is the value of the part after 
":" in the Host header value, if any, or the server port where the client 
connection was accepted on.
Returns:
an integer specifying the port number

Can you dump the values of ALL headers on the Tomcat side and post them?

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to