Use nginx with tomcat in linuix

Source: Internet
Author: User

1. Deploy Tomcat and nginx

2. modify the content in/CONF/server. xml under Tomcat instance server1:

<? XML version = '1. 0' encoding = 'utf-8'?> <Server port = "8200" shutdown = "shutdown"> <listener classname = "org. apache. catalina. core. aprlifecyclelistener "sslengine =" on "/> <listener classname =" org. apache. catalina. core. jasperlistener "/> <listener classname =" org. apache. catalina. core. jrememoryleakpreventionlistener "/> <listener classname =" org. apache. catalina. mbeans. serverlifecyclelistener "/> <listener classname =" org. apache. catalina. mbeans. GL Obalresourceslifecyclelistener "/> <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 "> <! -- For apache <connector Port = "8001" maxparametercount = "1000" protocol = "AJP/1.3" redirectport = "8443" maxsparethreads = "750" maxthreads = "1000" minsparethreads =" 50 "acceptcount =" 1000 "uriencoding =" GBK "usebodyencodingforuri =" true "/> --> <! -- For nginx --> <connector address = "127.0.0.1" Port = "8001" protocol = "HTTP/1.1" connectiontimeout = "20000" redirectport = "8444" uriencoding = "GBK" usebodyencodingforuri = "true"/> <! -- Note the difference with Apache. First, configure the address sub-element. Second Protocol, and redirectport instances are not repeated! --> <Engine name = "Catalina" defaulthost = "localhost" jvmroute = "S1"> <realm classname = "org. apache. catalina. realm. userdatabaserealm "resourcename =" userdatabase "/> 

3. Modify the server. xml of each Tomcat instance in sequence

4. Modify nginx configuration information

(1) Create the nginx/CONF/domain/directory, create the xxx.xxxx.com file under it (xxx.xxx.com is the test URL), and edit this file:

Upstream xxx.xxxx.com {# the IP address and port of the two Tomcat instances must be the same as that of the Tomcat server. in XML, the connnector element corresponds to server 127.0.0.1: 8001; server 127.0.0.1: 8002;} server {# nginx port listen 80; # SERVER_NAME xxx.xxx.com; # Log Path access_log/export/servers/nginx/logs/xxx.xxx.com; Location/{# Send the visitor's real IP address to the cluster's tomcat proxy_set_header X-real-IP $ remote_addr; # handle the visitor's IP proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for; proxy_set_header host xxx.xxx.com; proxy_pass http://xxx.xxx.com ;}}

(2) configure the nginx/CONF/nginx. conf file

####### Anged 2010-08-11 ######## user WWW; worker_processes 16; error_log/export/servers/nginx/logs/nginx_error.log warn; pid/export/servers/nginx/logs/nginx. PID; worker_rlimit_nofile 65535; events {use epoll; worker_connections 65535;} HTTP {include mime. types; default_type application/octet-stream; server_tokens off; log_format main '$ remote_addr-$ remote_user [$ time_local] ''" $ request "$ Status $ bytes_sent'' "$ http_referer" "$ http_user_agent" ''" $ gzip_ratio "'; # charset UTF-8; Limit 128; Limit 32 K; limit 4 32 K; client_max_body_size 300 m; sendfile on; tcp_nopush on; keepalive_timeout 10; tcp_nodelay on; Limit 512 K; limit on; proxy_connect_timeout 90; proxy_read_timeout 180; proxy_send_timeout 180; Limit 256 K; proxy_buffers 4 256 K; Limit 256 K; Limit 256 K; Disable off; proxy_hide_header X-powered-by; gzip on; gzip_min_length 100; gzip_buffers 4 16 K; gzip_http_version 1.0; gzip_comp_level 9; gzip_types text/plain application/X-JavaScript text/CSS application/XML; gzip_vary on; # include domains/xxx.xxx.com; ########### status ######## server {Listen 80; SERVER_NAME status.xxx.com; Location/{stub_status on; access_log off ;}}}

(5) release the project to the working directory specified by CONF/Catalina/localhost/root. XML in the Tomcat instance.

Generally:

<Context path="/" docBase="/export/data/tomcatRoot/xxx.xxx.com" ></Context>

(6) Start n Tomcat instances and start nginx .. test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.