玩转nginx nginx常用配置之负载均衡

nginx 作为静态文件服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
listen 8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
client_max_body_size 20m;

location / {
root /etc/nginx/html/store_app/dist/;
index index.html;
}

nginx 反向代理到上述节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
listen 8000;
root /etc/nginx/html/store_app;


location ~* /store_app/ {
autoindex on;
rewrite ^/(.*)$ http://10.10.10.36:8001 permanent;
break;
}

error_log /var/log/nginx/demo.log;
access_log /var/log/nginx/demo.log;
}

生产 nginx eywa 配置

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
upstream eywa {
server 192.168.10.125:8081;
server 192.168.20.115:8081;
ip_hash;
}

server {
listen 80;
server_name eywa.today36524.com

rewrite / https://eywa.today36524.com$uri permanent;

}

server {
listen 443 ssl;
server_name eywa.today36524.com;
ssl_certificate /etc/nginx/cert/today36524.com.pem;
ssl_certificate_key /etc/nginx/cert/today36524.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers xxxxxxxxxxxxx
xxxxxxx

access_log /var/log/nginx/eywa-443.log
error_log /var/log/nginx/eywa-error443.log

proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 6000;

gzip off;
gzip_buffers 16 8k;
gzip_comp_level 5;
gzip_




location /{
send_timeout 300;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwardad_for;

proxy_pass http://eywa;
}
}
文章目录
  1. 1. nginx 作为静态文件服务器
  2. 2. nginx 反向代理到上述节点
  3. 3. 生产 nginx eywa 配置
|