Home Backend Development PHP Tutorial Nginx+tomcat cluster environment construction

Nginx+tomcat cluster environment construction

Aug 08, 2016 am 09:26 AM
html nbsp nginx timeout tomcat

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

  1. b> Apache Tomcatb>td> changed to [html] view plaincopy b> Apache Tomcat 1
b

>

td

>

  1. Similarly, we put tomcat02’s D:tomcattomcat02webappsROOTindex.html in [html] view plaincopy
    1. b> Apache Tomcatb>td> changed to [html] view plaincopy b>
    2. Apache Tomcat 2
    b

    >

    td

    >
    1. 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">
    2. changed to

    [html] view plaincopy

      <
    1. Server port="8105"shutdown="SHUTDOWN">
[html] view plaincopy

<
  1. Connector port="8080"protocol="HTTP/1.1"                connectionTimeout=
"20000"
     

                

redirectPort

=
  1. "8443" />  changed to [html] view plaincopy
    1. <Connector port="8180" protocol="HTTP/1.1"   
    2.                connectionTimeout="20000"   
    3.                redirectPort="8543" />  


    1. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />  
    改为

    [html] view plaincopy

    1. <Connector port="8109" protocol="AJP/1.3" redirectPort="8543" />  


    [html] view plaincopy

    1.   
    2、  配置nginx

    nginx.conf

    [html] view plaincopy

    1. #Nginx user and group, not specified under window
    2. #user niumd niumd;
    3. #The number of working sub-processes (usually equal to the number of CPUs or 2 times the CPU)
    4. worker_processes 2;
    5. #Error log storage path
    6. #error_log logs/error.log;
    7. #error_log logs/error.log notice;
    8. #error_log logs/error.log info;
    9. #Specify pid to store files
    10. #pid logs/nginx.pid;
    11. events {
    12.    #When using the network IO model, Linux recommends epoll, FreeBSD recommends kqueue, and it is not specified under window.
    13. #use epoll;
    14. #Maximum number of connections allowed
    15. worker_connections 1024;
    16. }
    17. http {
    18. include mime.types;
    19. default_type application/octet-stream;
    20. #Define log format
    21. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    22.                    '$status                                                                                   
    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.          #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.​
    38.         #If the same machine is in multiple networks, the IP may be different when the route is switched
    39. ip_hash;
    40.                                                                                                                                                                                                 out out out way       off, ,         off off off surprise surpriselop off off exactly why zen to-
    41. C 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.                                                                                   ’ ’ s ’ s ’ ’ ’ 1 t           ’’ ’ ’ ’ ’ ’ ’ ’ ’ ’ 1 out out out out through'' ‐ ‐ ‐‐‐‐‐‐‐‐
    52.               proxy_pass  http://localhost;             
    53.           } 
    54. P #ERROR_PAGE 404 /404.html;
    55.         # redirect server error pages to the static page /50x.html
    56.             #
    57. error_page 500 502 503 504 /50x.html;
    58. Location = /50x.html {
    59. root html;
    60.           } 
    61. }
    62. }
    63. 3. View the reverse proxy configuration results Start nginx, tomcat01, tomcat02.
    64. 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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

See all articles