Objective:
For Javaer, the Nginx+tomcat cluster configuration has become the mainstream of Web application deployment. Big companies do, and so do small companies. For individual developers, resources are limited, and often multiple Web applications are mixed to a single server (cloud host), how to isolate access to these service resources? Do not affect each other? Nginx to solve for you, ^_^.
This article describes the simple configuration and deployment of Tomcat, and how nginx can be used as a reverse proxy.
Infrastructure:
The Unwritten convention:
1). A Tomcat container deploys a WebApp application instance
2). URL root Access webapp
In short, use Http://{host}:{port} to access the WebApp, not Http://{host}:{port}/{webapp}.
The root directory configuration for Tomcat:
The WebApp in Tomcat, which is the default Access URL rule, contains the name of the {WebApp}. So how do you implement root directory Access?
• Replace the root directory
In Tomcat, Webapps/root is done as its default root directory. Therefore, you can simply replace the corresponding webapp with the same name as root to reach the goal. Sparrow Jim, is a very good and shameless way.
• Add a context configuration item
In Conf/server.xml, locate the Host parent tab item and add a context item inside it.
For example, the configured entries are as follows:
Unpackwars= "false" autodeploy= "false" >
<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs"
prefix= "Localhost_access_log" suffix= ". txt"
pattern= "%h%l%u%t "%r" %s%b "/>
<!-Add this configuration entry, Docbase for the specified root path,
<context path= "" Docbase= "/path/to/webapppath/to/webapp"
debug= "0" crosscontext= "true"/>
</Host>
Note where the context is added , docbase is the corresponding directory for WebApp (remember that the extracted directory, not the war file).
In the actual production environment, Unpackwars and Autodeploy are often set to false, in order to prevent external illegal war injection attacks.
Nginx Distribution configuration:
Let us first talk about the domain name, and then to configure the specific nginx.conf.
*) domain name Assignment
Domain name is the basis and basis of nginx distribution. At the same time the domain name is a very cheap resource, this is a big premise.
There are often two ways to map a domain name to a webapp.
1) A first-level domain name corresponds to a webapp
Multiple domain names can be mapped to the same IP, and then the domain name corresponds to webapp one by one.
2) make full use of level two domain name
*) nginx configuration
In the HTTP configuration item, add a list of server items, each corresponding to a post-level service.
HTTP {# Other configuration item # WebApp backend a first-level domain name corresponds to a webappserver { listen; server_name domain1.com www.domain1.com; Location/{ proxy_pass http://127.0.0.1:8080; } } # WebApp Backend 2, # Use a level two domain name corresponding to a webappserver { listen; server_name appA.domain2.com; Location/{ proxy_pass http://127.0.0.1:8081;}} }
Note: server_name can be specified as a domain name or as an IP.
Specific nginx configuration details, will not be expanded.
Summarize:
There are few points involved in this article, that is, there is no specific meaning of nginx+tomcat configuration, and there is no deep nginx+tomcat performance tuning. But for mixed-webapp applications, the content involved can help you quickly implement multiple WebApp access isolation.
Public Number & Games sites:
Personal public Number: Wooden purpose H5 game world
For a personal game folio site , please click to visit : http://120.26.221.54/.
Nginx+tomcat cluster configuration (1)---root settings and multi-backend distribution configuration