开发者社区> 问答> 正文

linux下nginx负载均衡配置

请各位大虾高手帮助,nginx的负载均衡配置,不需要安装tomat等软件的。

做web的负载均衡,用nginx.conf配置文件弄的。

求解!

谢谢!

展开
收起
a123456678 2016-06-12 15:53:14 2825 0
2 条回答
写回答
取消 提交回答
  • 阿里云ping https://ping.gaomeluo.com/aliyun/

    参考:阿里云负载均衡怎么配置 https://yq.aliyun.com/articles/697165

    2019-07-17 19:34:21
    赞同 1 展开评论 打赏
  • # 配置 /usr/local/nginx/conf/nginx.conf
    
    
    #user nobody;
    
    worker_processes 4;
    
    #error_log logs/error.log;
    
    #error_log logs/error.log notice;
    
    #error_log logs/error.log info;
    
    #pid logs/nginx.pid;
    
    
    events {
    
    use epoll;
    
    worker_connections 10240;
    
    }
    
    
    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;
    
    client_max_body_size 10m;
    
    
    gzip on;
    
    #gzip_comp_level 4;
    
    gzip_proxied any;
    
    gzip_types text/plain text/css application/x-javascript application/javascript text/javascript application/json;
    
    
    #gzip_disable "MSIE [1-6]\.";
    
    #tcp_nopush on;
    
    
    #keepalive_timeout 0;
    
    keepalive_timeout 65;
    
    server_tokens off;
    
    
    proxy_cache_path cache levels=1:2 keys_zone=redmine:100m inactive=2m max_size=1g;
    
    
    server {
    
    listen 3000;
    
    server_name localhost;
    
    
    #charset utf-8;
    
    
    #access_log logs/host.access.log main;
    
    access_log off;
    
    
    location / {
    
    proxy_cache redmine;
    
    proxy_cache_valid 200 304 1m;
    
    
    proxy_pass http://backend;
    
    root html;
    
    index index.html index.htm;
    
    rewrite /download http://g.cn permanent;
    
    }
    
    
    #error_page 404 /404.html;
    
    
    # redirect server error pages to the static page /50x.html
    
    #
    
    error_page 500 502 503 504 /50x.html;
    
    location = /50x.html {
    
    root html;
    
    }
    
    
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    
    #
    
    #location ~ \.php$ {
    
    # proxy_pass http://127.0.0.1;
    
    #}
    
    
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    
    #
    
    #location ~ \.php$ {
    
    # root html;
    
    # fastcgi_pass 127.0.0.1:9000;
    
    # fastcgi_index index.php;
    
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    
    # include fastcgi_params;
    
    #}
    
    
    # deny access to .htaccess files, if Apache's document root
    
    # concurs with nginx's one
    
    #
    
    #location ~ /\.ht {
    
    # deny all;
    
    #}
    
    }
    
    
    upstream backend {
    
    ip_hash;
    
    server 127.0.0.1:3001 weight=4;
    
    server 127.0.0.1:3002 weight=6;
    
    }
    
    }
    2019-07-17 19:34:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
大规模场景下KubernetesService 负载均衡性能 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载