Home >Backend Development >PHP Tutorial >Using Niginx for load balancing under Linux

Using Niginx for load balancing under Linux

WBOY
WBOYOriginal
2016-07-28 08:28:071067browse

This article is a follow-up to the previous article. Three tomcat servers and one nginx server are installed on the Tencent cloud server. The nginx server is used to balance the access of the three tomcat servers. Getting started is still very simple. The key is to pay attention to some details. And improve subsequent learning

Enter conf/nginx.conf under the installation package. NoteIt must be under the installation package (mine is under installnginx), not conf under the source code. Modify the file to:

http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
<strong>    upstream nginxBalance {
       server 123.206.75.62:8080 weight=1;
       server 123.206.75.62:8180 weight=1;
       server 123.206.75.62:8280 weight=1;
    }</strong>
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            <strong>proxy_pass http://nginxBalance;</strong>
            root   html;
            index  index.html index.htm;
        }

Just add the few sentences in bold above. Then use ./nginx -s reload to restart nginx and you can see the effect after the load. The following is the effect after running:

 Linux下利用Niginx进行负载均衡

 Linux下利用Niginx进行负载均衡

 Linux下利用Niginx进行负载均衡

OK, the basic load balancing configuration is completed, and the rest is to learn more in depth

The above introduces the use of Niginx for load balancing under Linux, 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