前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nginx 负载均衡配置+使用方法

Nginx 负载均衡配置+使用方法

作者头像
双面人
发布2019-10-23 15:40:42
4630
发布2019-10-23 15:40:42
举报
文章被收录于专栏:热爱IT热爱IT
代码语言:javascript
复制
# 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 {
 #        }
 #    }
}
原文参考地址:https://blog.csdn.net/fatedant/article/details/82182057
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
负载均衡
负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档