Experimental environment: windows xp sp3
Nginx version: 1.5.12;
Download address: http://nginx.org/en/download.html
Tomcat version: 6.0.39
Download address: http://tomcat.apache.org/download-60.cgi
1. Configure nginx
1. Create an nginx folder in the root directory of drive D, and extract the downloaded nginx release package nginx-1.5.12.zip to this directory.
2. D:nginxnginx-1.5.12 directory structure
Nginx-
|_ docs Document directory
|
|_ nginx.exe main program
3. Start nginx
Starting nginx under windows is very simple, just double-click to run nginx.exe. Nginx runs on port 80 by default. To check whether nginx is started, we only need to enter http://localhost in the browser and you will see the following page, indicating that our nginx has been started.
1. Stop nginx
If you need to stop nginx, you need to open a command line window, enter the directory where nginx is decompressed, that is, enter the directory where the nginx.exe file is located, and enter the command nginx –s stop to stop nginx.
2. Cluster configuration
1. Configure tomcat
Create a tomcat folder in the root directory of drive D, and unzip two copies of the tomcat6.0.39 release package into this directory, naming them tomcat01 and tomcat02 respectively. In order to easily observe which tomcat we are accessing, we modify the D:tomcattomcat01webappsROOTindex.html of tomcat01
[html] view
plaincopy
-
b> Apache Tomcatb>td>
changed to
[html] view
plaincopy
b> Apache Tomcat 1
b>
td
>
-
Similarly, we put tomcat02’s D:tomcattomcat02webappsROOTindex.html in
[html] view
plaincopy
-
b> Apache Tomcatb>td>
changed to
[html] view
plaincopy
b>
Apache Tomcat 2
b>
td>
-
We have two tomcats on the same computer. In order to prevent the ports of the two tomcats from conflicting, we put tomcat02’s D:tomcattomcat02confserver.xml
[html] view
plaincopy
<Server port="8005"shutdown="SHUTDOWN">
changed to
[html] view
plaincopy
<- Server port="8105"shutdown="SHUTDOWN">
[html] view
plaincopy
<- Connector port="8080"protocol="HTTP/1.1"
connectionTimeout=
"20000"
redirectPort=- "8443" />
changed to
[html] view
plaincopy
-
<Connector port="8180" protocol="HTTP/1.1"
-
connectionTimeout="20000"
-
redirectPort="8543" />
-
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
改为
[html] view
plaincopy
-
<Connector port="8109" protocol="AJP/1.3" redirectPort="8543" />
[html] view
plaincopy
-
2、 配置nginx
nginx.conf
[html] view
plaincopy
-
#Nginx user and group, not specified under window
-
#user niumd niumd;
-
-
#The number of working sub-processes (usually equal to the number of CPUs or 2 times the CPU)
-
worker_processes 2;
-
-
#Error log storage path
-
#error_log logs/error.log;
-
#error_log logs/error.log notice;
-
#error_log logs/error.log info;
-
-
#Specify pid to store files
-
#pid logs/nginx.pid;
-
-
-
events {
-
#When using the network IO model, Linux recommends epoll, FreeBSD recommends kqueue, and it is not specified under window.
-
#use epoll;
-
-
#Maximum number of connections allowed
-
worker_connections 1024;
-
}
-
-
-
http {
-
include mime.types;
-
default_type application/octet-stream;
-
-
#Define log format
-
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
-
'$status
- '"$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 { -
#Allocate requests to each backend tomcat based on IP calculation. Many people mistakenly believe that it can solve the session problem, but it does not.
-
#If the same machine is in multiple networks, the IP may be different when the route is switched
-
ip_hash;
-
out out out way off, , off off off surprise surpriselop off off exactly why zen to-
C 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; -
’ ’ s ’ s ’ ’ ’ 1 t ’’ ’ ’ ’ ’ ’ ’ ’ ’ ’ 1 out out out out through'' ‐ ‐ ‐‐‐‐‐‐‐‐
-
proxy_pass http://localhost;
-
}
-
-
P #ERROR_PAGE 404 /404.html;
-
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- Location = /50x.html {
-
root html; -
}
-
} -
} -
-
3. View the reverse proxy configuration results
Start nginx, tomcat01, tomcat02.
-
Enter http://localhost in the browser and you will see the management interface of tomcat01, as shown below.
Then transparently stop tomcat02, refresh the page, and nginx automatically switches to tomcat02 for us, as shown below.
The above introduces the establishment of Nginx+tomcat cluster environment, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn