Nginx Load Balancing

Source: Internet
Author: User
Tags sendfile nginx load balancing

Lab Environment

Win7 + ubuntu (VMware)

Win7 Tomcat (IP and por: 192.168.0.108: 8080)

Linux Tomcat (IP and por: 192.168.110.129: 8080)

Install nginx (SUDO apt-Get install nginx) In ubuntu. It is installed in ETC/nginx by default.

In the rootstores of two Tomcat webstores, the corresponding Tomcat is replaced by index.html and index. jsp, which are written to Linux and Windows respectively.

The command for disabling nginx startup and testing is as follows:

Disable nginxzhengx @ zhengx-Virtual-machine :~ $ Sudo pkill-9 check whether nginx is successfully configured with zhengx @ zhengx-Virtual-machine :~ $ Sudo nginx-tngting: [warn] conflicting server name "localhost" on 0.0.0.0: 80, ignorednginx: the configuration file/etc/nginx. conf syntax is oknginx: configuration file/etc/nginx. conf test is successful enable nginxzhengx @ zhengx-Virtual-machine :~ $ Sudo nginx: [warn] conflicting server name "localhost" on 0.0.0.0: 80, ignoredzhengx @ zhengx-Virtual-machine :~ $

 

The configuration file of nginx. conf is as follows:

User www-data; worker_processes 4; PID/var/run/nginx. PID; events {worker_connections 768; # multi_accept on;} HTTP {sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 1024; Include/etc/nginx/mime. types; default_type application/octet-stream; access_log/var/log/nginx/access. log; error_log/var/log/nginx/error. log; gzip on; upstream localhost {# Tomcat access URL se of win7 Rver 192.168.0.108: 8080; # Linux Tomcat access URL server 192.168.110.129: 8080;} server {Listen 80; SERVER_NAME localhost; charset UTF-8; Location/{root HTML; index index.html index.htm; # Jump to Tomcat proxy_pass http: // 192.168.0.108: 8080 on win7; proxy_set_header X-real-IP $ remote_addr; client_max_body_size 100 m;} location ~ ^/(WEB-INF)/{deny all;} error_page 500 502 503 x.html; location =/50x.html {root HTML;} include/etc/nginx/server. conf; Include/etc/nginx/CONF. d /*. conf; Include/etc/nginx/sites-enabled /*;}

For ease of maintenance, part of the nginx. conf code is split into upstream. conf and location. conf.

The configuration file of nginx. conf is as follows:

user www-data;worker_processes 4;pid /var/run/nginx.pid;events {worker_connections 768;# multi_accept on;}http {sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 65;types_hash_max_size 1024;include /etc/nginx/mime.types;default_type application/octet-stream;access_log /var/log/nginx/access.log;error_log /var/log/nginx/error.log;gzip on;include /etc/nginx/upstream.conf;server {  listen 80;  server_name  localhost;  charset utf-8;  include /etc/nginx/location.conf;    }  include /etc/nginx/conf.d/*.conf;include /etc/nginx/sites-enabled/*;}

The configuration file of upstream. conf is as follows:

upstream   localhost {                server   192.168.0.108:8080;                server   192.168.110.129:8080;  }  

The configuration file of location. conf is as follows:

Location/{root HTML; index index.html index.htm; # Find the upstream proxy_pass http: // localhost; proxy_set_header X-real-IP $ remote_addr; client_max_body_size 100 m ;} location ~ ^/(WEB-INF)/{deny all;} error_page 500 502 503 x.html; location =/50x.html {root HTML ;}

 

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.