您好,登录后才能下订单哦!
本篇内容主要讲解“Nginx负载均衡的配置和使用方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Nginx负载均衡的配置和使用方法”吧!
# 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负载均衡的配置和使用方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。