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
- #Nginx所用用户和组, not specified under window
- #user NIUMD NIUMD;
- #工作的子进程数量 (usually equal to the number of CPUs or twice times the CPU)
- Worker_processes 2;
- #错误日志存放路径
- #error_log Logs/error.log;
- #error_log Logs/error.log Notice;
- #error_log Logs/error.log Info;
- #指定pid存放文件
- #pid Logs/nginx.pid;
- Events {
- #使用网络IO模型linux建议epoll, FreeBSD recommends using Kqueue,window not specified.
- #use Epoll;
- #允许最大连接数
- Worker_connections 1024;
- }
- HTTP {
- Include Mime.types;
- Default_type Application/octet-stream;
- #定义日志格式
- 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;
- Client_header_timeout 3m;
- Client_body_timeout 3m;
- Send_timeout 3m;
- Client_header_buffer_size 1k;
- Large_client_header_buffers 4 4k;
- Sendfile on;
- Tcp_nopush on;
- Tcp_nodelay on;
- #keepalive_timeout 0;
- Keepalive_timeout 65;
- #gzip on;
- Upstream localhost {
- #根据ip计算将请求分配各那个后端tomcat, many people mistakenly think that can solve the session problem, in fact, can not.
- #同一机器在多网情况下, routing switching, IP may be different
- Ip_hash;
- Server localhost:8080;
- Server localhost:8180;
- }
- server {
- Listen 80;
- server_name localhost;
- #charset Koi8-r;
- #access_log Logs/host.access.log Main;
- Location/{
- Proxy_connect_timeout 3;
- Proxy_send_timeout 30;
- Proxy_read_timeout 30;
- Proxy_pass http://localhost;
- }
- #error_page 404/404.html;
- # REDIRECT Server error pages to the static page/50x.html
- #
- Error_page 502 503 504/50x.html;
- Location =/50x.html {
- root HTML;
- }
- }
- }
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)