The integration of Tomcat and nginx windows

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Tomcat comes with the Apache server for processing concurrent requests are relatively poor, and resource consuming greatly, while nginx this convenient but very tough, the following is the process of the integration of Tomcat and nginx under Windows.

1.Preparation work

Download Tomcat(,Download nginx (), I use the version of Tomcat 7, nginx 0.8.54, Tomcat and nginx were extracted, to separate directory, the directory is I unpack

The 2 configuration Tomcat, Next, need to change the default ROOT directory tomcat, point to the nginx directory.

Open the tomcat/conf/server.xml file. Find<Host>Tag, in<Host>To add the following content.

<Context path="" docBase="F:\service\nginx-0.8.54\html\www" reloadable="true"></Context>
Remember to save, the meaning of this sentence is, in the main, open the site for " F:\service\nginx-0.8.54\html\www" under the directory


Next, we need in this directory (" F:\service\nginx-0.8.54\html\www") in a new test for the index.jsp file.

Index.jsp can be a few simple words can be used to test:

<!DOCTYPE html>

<html lang="en">




<h3>this is Tomcat 1+2 = <%=1+2%></h3>



Then we can open the Tomcat (tomcat/bin following startup.bat double click on the OK). The default port is 8080.
Open the server, we can open the browser localhost:8080 test Tomcat is configured correctly.
If appeared above the page, the Tomcat configuration is successful, we can put down the Tomcat.

3.The configuration of nginx,

Open the nginx/conf/nginx.conf file, this file is the core of the configuration file of nginx server.

The content inside replaced

#user nobody;

worker_processes 1;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/;

events {

worker_connections 1024;


http {

include mime.types;

default_type application/octet-stream;

include proxy.conf; #This file is our new, to import

log_format main '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

access_log logs/access.log main;

sendfile on;

tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html\www;

index index.jsp index.html index.htm;


location ~ .*.jsp$ { #Matching end with JSP, Tomcat Webpage file ending in JSP

index index.jsp;

proxy_pass http://localhost:8080; #Mainly in here, set up a proxy


location /nginxstatus {

stub_status on;

access_log on;

auth_basic "nginxstatus";

auth_basic_user_file htpasswd;


# redirect server error pages to the static page /50x.html


#error_page 500 502 503 504 /50x.html;

#error_page 404 /404.html;

location = /50x.html {

root html;


# proxy the PHP scripts to Apache listening on


#location ~ \.php$ {

# proxy_pass ;


# pass the PHP scripts to FastCGI server listening on


#location ~ \.php$ {

# root html;

# fastcgi_pass;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;


# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one


#location ~ /\.ht {

# deny all;



# another virtual host using mix of IP-, name-, and port-based configuration


#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;

# location / {

# root html;

# index index.html index.htm;

# }


# HTTPS server


#server {

# listen 443;

# server_name localhost;

# ssl on;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;

# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }




In the conf folder to build a file proxy.conf, as follows

# proxy.conf

proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr; #Get real IP

#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #Gets the agent of the real IP

client_max_body_size 10m;

client_body_buffer_size 128k;

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffer_size 4k;

proxy_buffers 4 32k;

proxy_busy_buffers_size 64k;

proxy_temp_file_write_size 64k;


Double click the nginx.exe, start the server, the default port for nginx is 80, so the Tomcat will not conflict, if Tomcat is 80, then you need to adjust.

Open the browser, enter localhost, if we see the following, said configuration succeeded, as shown in Fig.


This is the error page nginx by default, as shown in Fig.


At this point, Tomcat and nginx has been integrated successfully.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by natascha at March 05, 2014 - 3:08 AM