[Nginx] - 负载均衡配置

nginx.conf文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
user  www www;
worker_processes  2;
 
error_log  /usr/local/nginx/logs/serror.log crit;
pid        /usr/local/nginx/logs/nginx.pid;
 
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
 
events
{
  use epoll;
  worker_connections 65535;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #charset  gb2312;
 
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
 
    sendfile on;
    tcp_nopush     on;
 
    keepalive_timeout 60;
 
    tcp_nodelay on;
 
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
 
    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    #limit_zone  crawler  $binary_remote_addr  10m;
    log_format '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
    include /usr/local/nginx/conf/vhosts/*.conf;
}

 

在vhosts目录下的conf文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
upstream slave {
    server xxx.xxx.xxx.xxx max_fails=3 fail_timeout=30s weight=5;
    server xxx.xxx.xxx.xxx max_fails=3 fail_timeout=30s weight=5;
}
 
server {
    listen  80;
    server_name  www.XXX.com;
     
    #if ($uri ~* "(/login$|/login.html$|/login/index.html$|/admin/.+|/signup$|/signup/.+$|/signup.html$)") {
    #   return  301 https://$server_name$request_uri;
    #}
 
    location / {
        client_max_body_size 200m;
        proxy_pass http://slave;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_body_buffer_size 128k;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        proxy_buffer_size 64k;
        proxy_buffers 4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
    }
 
    location = /50x.html {
        root   html;
    }
}
 
server{
    listen 443;
    ssl on;
    ssl_certificate /alidata/ssl/server.crt;
    ssl_certificate_key /alidata/ssl/server.key;
    server_name  www.XXX.com;
     
    #if ($uri !~* "(/login$|/login.html$|/login/index.html$|/static/.+|/common/api/.+|/admin/.+|/signup$|/signup/.+$|/signup.html$)") {
    #   return  301 http://$server_name$request_uri;
    #}
 
    location / {
        client_max_body_size 200m;
        proxy_pass http://slave;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_body_buffer_size 128k;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        proxy_buffer_size 64k;
        proxy_buffers 4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
    }
 
    location = /50x.html {
        root   html;
    }
}

  

posted @   横渡  阅读(805)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
阅读排行:
· 【译】我们最喜欢的2024年的 Visual Studio 新功能
· 个人数据保全计划:从印象笔记迁移到joplin
· Vue3.5常用特性整理
· 重拾 SSH:从基础到安全加固
· 为什么UNIX使用init进程启动其他进程?
历史上的今天:
2005-07-06 [随文杂记]这一棒打醒了我,打酸了心。
点击右上角即可分享
微信分享提示