开发者社区> 问答> 正文

linux下nginx负载均衡配置

a123456678 2016-06-12 15:53:14 1280

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

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

求解!

谢谢!

负载均衡 应用服务中间件 Linux nginx
分享到
取消 提交回答
全部回答(2)
  • 搞么罗
    2019-07-17 19:34:21

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

    1 0
  • a123456678
    2019-07-17 19:34:21
    # 配置 /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;
    
    }
    
    }
    0 0
添加回答

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程