Turn "NGINX+TOMCAT cluster environment Setup (under Windows)

Source: Internet
Author: User
Tags apache tomcat

Original blog from: http://blog.csdn.net/clj198606061111/article/details/22621003 thanks!

Experimental environment

Windows XP SP3

Nginx version: 1.5.12;

: http://nginx.org/en/download.html

Tomcat version: 6.0.39

: http://tomcat.apache.org/download-60.cgi

First, the configuration Nginx

1, in the D packing directory to establish Nginx folder, the download Nginx release package Nginx-1.5.12.zip extracted to the directory.

2. D:\NGINX\NGINX-1.5.12 directory Structure

nginx-

|_ conf Configuration directory

|_ contrib.

|_ Docs Documentation Directory

|_ Logs Log directory
|_ Temp Temporary file directory

|_ HTML Static page directory

|_ Nginx.exe Main Program

3. Start Nginx

Windows Start Nginx is very simple, double-click Run Nginx.exe can. Nginx is running on the 80 port by default, check if Nginx is started we only need to enter http://localhost in the browser to see the following page, indicating that our nginx has been set up.

1. Stop Nginx

If you need to stop nginx, you need to open a command line window, into the Nginx decompression directory, that is, enter the directory where the Nginx.exe file, enter the command nginx–s stop can stop nginx.

Second, cluster configuration

1. Configuring Tomcat

Build the Tomcat folder in the D packing directory and extract 2 copies of the tomcat6.0.39 release package to this directory, named Tomcat01,tomcat02. To make it easy to see which Tomcat we're visiting, we modified TOMCAT01 's D:\tomcat\tomcat01\webapps\ROOT\index.html

<td align= "left"  valign= "top" span class= "tag" >><b>apache tomcat< span class= "tag" ></b></ td>  

<TD Align="left" valign="Top"><b>apache Tomcat 1</b ></td>

In the same vein, we put Tomcat02 's D:\tomcat\tomcat02\webapps\ROOT\index.html

< span class= "tag" ><td align= "left"  valign= "top" span class= "tag" >><b>apache tomcat< span class= "tag" ></b></ td>  

Switch

<TD Align="left" valign="Top"><b>apache Tomcat 2</b ></td>

2 Tomcat we are on the same computer, in order to let 2 tomcat ports do not conflict, we put tomcat02 in the D:\tomcat\tomcat02\conf\server.xml

<Server port="8005" shutdown="shutdown">

Switch

<Server port="8105" shutdown="shutdown">

<Connector port="8080" protocol="http/1.1 "

connectiontimeout="20000"

    redirectport="8443" />

Switch

<Connector port="8180" protocol="http/1.1 "

connectiontimeout="20000"

    redirectport="8543" />

<Connector port="8009" protocol="ajp/1.3" redirectport="8443" />

Switch

<Connector port="8109" protocol="ajp/1.3" redirectport="8543" />

2. Configure Nginx

Nginx.conf

  1. #Nginx所用用户和组, not specified under window
  2. #user NIUMD NIUMD;
  3. #工作的子进程数量 (usually equal to the number of CPUs or twice times the CPU)
  4. Worker_processes 2;
  5. #错误日志存放路径
  6. #error_log Logs/error.log;
  7. #error_log Logs/error.log Notice;
  8. #error_log Logs/error.log Info;
  9. #指定pid存放文件
  10. #pid Logs/nginx.pid;
  11. Events {
  12. #使用网络IO模型linux建议epoll, FreeBSD recommends using Kqueue,window not specified.
  13. #use Epoll;
  14. #允许最大连接数
  15. Worker_connections 1024;
  16. }
  17. HTTP {
  18. Include Mime.types;
  19. Default_type Application/octet-stream;
  20. #定义日志格式
  21. Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
  22. ' $status $body _bytes_sent ' $http _referer '
  23. ' "$http _user_agent" "$http _x_forwarded_for";
  24. Access_log Logs/access.log Main;
  25. Client_header_timeout 3m;
  26. Client_body_timeout 3m;
  27. Send_timeout 3m;
  28. Client_header_buffer_size 1k;
  29. Large_client_header_buffers 4 4k;
  30. Sendfile on;
  31. Tcp_nopush on;
  32. Tcp_nodelay on;
  33. #keepalive_timeout 0;
  34. Keepalive_timeout 65;
  35. #gzip on;
  36. Upstream localhost {
  37. #根据ip计算将请求分配各那个后端tomcat, many people mistakenly think that can solve the session problem, in fact, can not.
  38. #同一机器在多网情况下, routing switching, IP may be different
  39. Ip_hash;
  40. Server localhost:8080;
  41. Server localhost:8180;
  42. }
  43. server {
  44. Listen 80;
  45. server_name localhost;
  46. #charset Koi8-r;
  47. #access_log Logs/host.access.log Main;
  48. Location/{
  49. Proxy_connect_timeout 3;
  50. Proxy_send_timeout 30;
  51. Proxy_read_timeout 30;
  52. Proxy_pass http://localhost;
  53. }
  54. #error_page 404/404.html;
  55. # REDIRECT Server error pages to the static page/50x.html
  56. #
  57. Error_page 502 503 504/50x.html;
  58. Location =/50x.html {
  59. root HTML;
  60. }
  61. }
  62. }

3. View reverse proxy configuration results

Start Nginx, tomcat01, tomcat02.

Browser input http://localhost will see the tomcat01 management interface, such as.

Then transparent stop tomcat02, refresh the page, Nginx automatically help us to switch to tomcat02, such as.

Go to Nginx+tomcat cluster environment (under Windows)

Related Article

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.