Nginx负载均衡的配置和使用方法

本篇内容主要讲解“Nginx负载均衡的配置和使用方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Nginx负载均衡的配置和使用方法”吧!

创新互联是一家专注于成都网站设计、成都网站制作与策划设计,桥东网站建设哪家好?创新互联做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:桥东等地区。桥东做网站价格咨询:18980820575

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

//////负载均衡的关键【要在http里面】
    upstream group{
    server 192.168.0.180:80;
    server 192.168.0.181:80;
}


    server {
        listen       80;
        listen       [::]:80 default_server;
        server_name  _;
        root         /var/www/html;
    index index.php

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

       location / {  
    proxy_pass http://group;//负衡均衡跳转group对应 upstream 后面的名称,如果不用负载均衡可用下面两行屏蔽的直接引到对应目录 
           # root   /var/www/html;  
           # index  index.php index.html index.htm;  
        }   

    location ~ \.php$ {  
            root           /var/www/html;  
            fastcgi_pass   127.0.0.1:9000;  
            fastcgi_index  index.php;  
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
            fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;  
            include        fastcgi_params;  
        }  

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

到此,相信大家对“Nginx负载均衡的配置和使用方法”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


网站名称:Nginx负载均衡的配置和使用方法
文章路径:http://pwwzsj.com/article/pcoedd.html