Nginx + tomcat load balancing

Source: Internet
Author: User
: This article mainly introduces nginx + tomcat server load balancer. if you are interested in the PHP Tutorial, refer to it. I. environment introduction

1. a total of three virtual machines (rhel6.2-64) in this experiment)

192.168.232.147 (nginx)

192.168.232.154 (tomcat)

192.168.232.155 (tomcat)

2. install and configure JDK

3. configure related environment variables (profile, hosts)

4. prepare a web project to test whether server load balancer works. this experiment uses a previously written permission management module.

II. install and configure tomcat

1. install tomcat on machines 192.168.232.154 and 192.168.232.155

2.download a Linux-based apache-tomcat-7.0.64.tar.gz file to decompress it.

3. in Label

 

4. create the/root/webapps directory and put the permission web project under this directory, start tomcat, and access

Http: // 192.168.232.154: 8080/, http: // 192.168.232.154: 8080/You can access the homepage of the permission project

3. install and configure Nginx

1. download nginx-1.2.6.tar.gz and decompress it to the specified directory.

2. ensure that the nginx compiling environment is ready for running.

3. install pcre-devel openssl-devel

(1) configure the local yum so that the yum installation package can be found

(2) installation: yum-y install pcre-devel openssl-devel

4. create a www user: useradd www

5. prepare the compiling and installation environment

./Configure -- user = www -- group = www -- prefix =/usr/local/nginx -- with-http_stub_status_module -- with-http_ssl_module

6. Compile and install, enter the nginx decompressed root directory: cd/root/app/nginx-1.2.6

Make & make install

7. check whether nginx installation is successful

[Root @ storm1 nginx-1.2.6] #/usr/local/nginx/sbin/nginx-t
Nginx: the configuration file/usr/local/nginx/conf/nginx. conf syntax is OK
Nginx: configuration file/usr/local/nginx/conf/nginx. conf test is successful

8. visit the nginx default homepage: http: // 192.168.232.147: 80/. you can see the nginx welcome homepage.

Nginx installation is complete.

4. Configure nginx + tomcat integration. you only need to configure nginx and tomcat.

1. go to the directory specified for installation:/usr/local/nginx, and change nginx. conf to the following:

user  www www;worker_processes  1;pid     /usr/local/nginx/logs/nginx.pid;events {    use epoll;    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    include     /usr/local/nginx/conf/proxy.conf;    sendfile        on;    tcp_nopush      on;    keepalive_timeout  65;    log_format  $upstream_addr  $status $request_time   $time_local     $remote_user    $http_user_agent;    upstream panguoyuan.com {      server  192.168.232.154:8080;      server  192.168.232.155:8080;                }        server{            listen 80;            server_name panguoyuan.com;            location / {                proxy_pass         http://panguoyuan.com;                proxy_set_header   Host             $host;                proxy_set_header   X-Real-IP        $remote_addr;                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;            }        }}

2. the hosts on 192.168.232.147 is as follows:

[Root @ storm1 conf] # cat/etc/hosts
192.168.232.147 storm1
192.168.232.154 storm2
192.168.232.155 storm3
192.168.232.147 panguoyuan.com

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces nginx + tomcat load balancing, including some content, hope to be helpful to friends who are interested in PHP tutorials.

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.