Nginx load balancing configuration

Source: Internet
Author: User
Tags nginx load balancing
: This article mainly introduces nginx server load balancer configuration. if you are interested in the PHP Tutorial, refer to it. I. INTRODUCTION

Tomcat has low performance when handling dynamic requests in high concurrency environments, but is more vulnerable to processing static pages. Although the latest version of Tomcat supports epoll, it is much better to process static pages through Nginx than to process static pages through Tomcat.

II. download and install (take windows as an example)

1,
: Click here

2. directory structure

Nginx-| _ conf configuration directory | _ contrib | _ docs document directory | _ logs log directory | _ temp temporary file directory | _ html static page directory | _ nginx.exe main program

III. start and stop the nginx service

Cmd enter the nginx decompression Directory

Run start nginxto start the service (nginx nginx.exe)
We recommend that you use the first method,
The other two methods keep your cmd window in the running state and do not support other command operations.

Run nginx-s stop to stop the nginx service.

Run nginx-t to check whether the nginx configuration file is correct.

IV. nginx main configuration file nginx. conf

Click here to download all configuration files

# Users and Groups used by Nginx # user niumd; # 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 the pid to store the file pid logs/nginx. pid; events {# epoll is recommended for linux using the network I/O model. for FreeBSD, kqueue # use epoll; # worker_connections 2048;} http {include mime. types; default_type application/octet-stream; # define Log Format # 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 off; access_log logs/access. log; client_header_timeout 3 m; latency 3 m; send_timeout 3 m; latency 1 k; latency 44 k; sendfile on; tcp_nopush on; tcp_nodelay on; # keepalive_timeout 75 20; include gzip. conf; upstream localhost {server localhost: 8080 weight = 5; server localhost: 9091 weight = 1;} server {listen 80; server_name localhost; location/{proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://localhost ;}}}

5. load balancing weight configuration

    upstream localhost {      server localhost:8080 weight=5;      server localhost:9091 weight=1;     }

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces the nginx server load balancer configuration, including some content, hope to be helpful to friends who are interested in the PHP Tutorial.

    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.