当前位置:   article > 正文

阿里云配置nginx反向代理tomcat_阿里云反向代理配置tomcat

阿里云反向代理配置tomcat

1、配置tomcat 域名+端口直接访问

        修改server.xml如下:

       

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- Note: A "Server" is not itself a "Container", so you may not
  17. define subcomponents such as "Valves" at this level.
  18. Documentation at /docs/config/server.html
  19. -->
  20. <Server port="8005" shutdown="SHUTDOWN">
  21. <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  22. <!-- Security listener. Documentation at /docs/config/listeners.html
  23. <Listener className="org.apache.catalina.security.SecurityListener" />
  24. -->
  25. <!--APR library loader. Documentation at /docs/apr.html -->
  26. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  27. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  28. <Listener className="org.apache.catalina.core.JasperListener" />
  29. <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  30. <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  31. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  32. <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  33. <!-- Global JNDI resources
  34. Documentation at /docs/jndi-resources-howto.html
  35. -->
  36. <GlobalNamingResources>
  37. <!-- Editable user database that can also be used by
  38. UserDatabaseRealm to authenticate users
  39. -->
  40. <Resource name="UserDatabase" auth="Container"
  41. type="org.apache.catalina.UserDatabase"
  42. description="User database that can be updated and saved"
  43. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  44. pathname="conf/tomcat-users.xml" />
  45. </GlobalNamingResources>
  46. <!-- A "Service" is a collection of one or more "Connectors" that share
  47. a single "Container" Note: A "Service" is not itself a "Container",
  48. so you may not define subcomponents such as "Valves" at this level.
  49. Documentation at /docs/config/service.html
  50. -->
  51. <Service name="Catalina">
  52. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  53. <!--
  54. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  55. maxThreads="150" minSpareThreads="4"/>
  56. -->
  57. <!-- A "Connector" represents an endpoint by which requests are received
  58. and responses are returned. Documentation at :
  59. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  60. Java AJP Connector: /docs/config/ajp.html
  61. APR (HTTP/AJP) Connector: /docs/apr.html
  62. Define a non-SSL HTTP/1.1 Connector on port 8080
  63. -->
  1. <Connector port="9090" protocol="HTTP/1.1"
  2. connectionTimeout="20000"
  3. redirectPort="8443" />
  4. <!-- A "Connector" using the shared thread pool-->
  5. <!--
  6. <Connector executor="tomcatThreadPool"
  7. port="8080" protocol="HTTP/1.1"
  8. connectionTimeout="20000"
  9. redirectPort="8443" />
  10. -->
  11. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  12. This connector uses the BIO implementation that requires the JSSE
  13. style configuration. When using the APR/native implementation, the
  14. OpenSSL style configuration is required as described in the APR/native
  15. documentation -->
  16. <!--
  17. <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
  18. maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
  19. clientAuth="false" sslProtocol="TLS" />
  20. -->
  21. <!-- Define an AJP 1.3 Connector on port 8009 -->
  22. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  23. <!-- An Engine represents the entry point (within Catalina) that processes
  24. every request. The Engine implementation for Tomcat stand alone
  25. analyzes the HTTP headers included with the request, and passes them
  26. on to the appropriate Host (virtual host).
  27. Documentation at /docs/config/engine.html -->
  28. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  29. <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  30. -->
  31. <Engine name="Catalina" defaultHost="localhost">
  32. <!--For clustering, please take a look at documentation at:
  33. /docs/cluster-howto.html (simple how to)
  34. /docs/config/cluster.html (reference documentation) -->
  35. <!--
  36. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  37. -->
  38. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  39. via a brute-force attack -->
  40. <Realm className="org.apache.catalina.realm.LockOutRealm">
  41. <!-- This Realm uses the UserDatabase configured in the global JNDI
  42. resources under the key "UserDatabase". Any edits
  43. that are performed against this UserDatabase are immediately
  44. available for use by the Realm. -->
  45. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  46. resourceName="UserDatabase"/>
  47. </Realm>
  48. <Host name="localhost" appBase="webapps"
  49. unpackWARs="true" autoDeploy="true">
  50. <Context path="" docBase="/usr/share/tomcat/webapps/jinju" debug="0" reloadable="true"/>
  51. <!-- SingleSignOn valve, share authentication between web applications
  52. Documentation at: /docs/config/valve.html -->
  53. <!--
  54. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  55. -->
  56. <!-- Access log processes all example.
  57. Documentation at: /docs/config/valve.html
  58. Note: The pattern used is equivalent to using pattern="common" -->
  59. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  60. prefix="localhost_access_log." suffix=".txt"
  61. pattern="%h %l %u %t "%r" %s %b" />
  62. </Host>
  63. </Engine>
  64. </Service>
  65. </Server>
<Connector port="9090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <!-- A "Connector" using the shared thread pool--> <!-- <Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> --> <!-- Define a SSL HTTP/1.1 Connector on port 8443 This connector uses the BIO implementation that requires the JSSE style configuration. When using the APR/native implementation, the OpenSSL style configuration is required as described in the APR/native documentation --> <!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> --> <!-- Define an AJP 1.3 Connector on port 8009 --> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <!-- An Engine represents the entry point (within Catalina) that processes every request. The Engine implementation for Tomcat stand alone analyzes the HTTP headers included with the request, and passes them on to the appropriate Host (virtual host). Documentation at /docs/config/engine.html --> <!-- You should set jvmRoute to support load-balancing via AJP ie : <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> --> <Engine name="Catalina" defaultHost="localhost"> <!--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="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/usr/share/tomcat/webapps/jinju" debug="0" 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> </Service> </Server>
改过的部分已经加粗。

重启tomcat即可直接访问tomcat项目


2、配置nginx
   在配置目录下新建配置文件
  1. #stream name is www.way-voice.com
  2. # and my blog express app is running under port 3000
  3. upstream way-voice.com{
  4.     server 127.0.0.1:9090;
  5.     keepalive 8;
  6. }
  7. # the nginx server instance
  8. server {
  9.     listen  80;
  10.     server_name    way-voice.com;
  11.     location / {
  12.       proxy_set_header X-Real-IP $remote_addr;
  13.       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  14.       proxy_set_header Host $http_host;
  15.       proxy_set_header X-NginX-Proxy true;
  16.       # value for proxy_pass has to match upstream name
  17.       proxy_pass http://way-voice.com;
  18.       proxy_redirect off;
  19.     }
  20.  }
server 127.0.0.1:9090;     keepalive 8; } # the nginx server instance server {     listen  80;     server_name    way-voice.com;     location / {       proxy_set_header X-Real-IP $remote_addr;       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       proxy_set_header Host $http_host;       proxy_set_header X-NginX-Proxy true;       # value for proxy_pass has to match upstream name       proxy_pass http://way-voice.com;       proxy_redirect off;     }  }
需要注意的地方已经加粗。
最后在nginx.conf中的http模块在include该配置文件
 include   /etc/nginx/jinju/*.conf;


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/77549
推荐阅读
相关标签
  

闽ICP备14008679号